Forums

PHP

This topic is locked

Convert from ASP to PHP

Posted 24 Jul 2006 16:11:18
1
has voted
24 Jul 2006 16:11:18 Panayiotis Savva posted:
Hi, I've been struggling for days trying to convert this simple piece of code to PHP :'(

I simply don't understand the PHP syntax when it comes to request variables and querystrings...

This is the code:


Dim responsetext
Dim XmlHttp
Dim Getpage
Dim affiliate
affiliate=530
myquery="?affiliate="&affiliate&"&"
for i=1 to Request.querystring.count
myquery=myquery&(Request.querystring.Key(i)&"="&Request.querystring.Item(i)&""
if not(i=Request.querystring.count) then
myquery=myquery&"&"
end if
next
Getpage = "mysite.com/aff/"&myquery
Set XmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP"
XmlHttp.Open "GET", Getpage, False
XmlHttp.Send
responsetext = XmlHttp.ResponseText
response.write(responsetext)





This is my attempt :'(

<?
$affiliate=530;
$myquery="?affiliate=".$affiliate."&";
for ($i=1; $i<=count($_GET); $i=$i+1)
{
$myquery=$myquery.(($i)."=".($i)."";
if (!($i==count($_GET)))
{
$myquery=$myquery."&";
}
}
$Getpage="mysite.com/aff/".$myquery;
//REALLY STUCK HERE
?>

Replies

Replied 24 Jul 2006 16:56:38
24 Jul 2006 16:56:38 Roddy Dairion replied:
What outcome are you looking to get?
<pre id=code><font face=courier size=2 id=code>
&lt;?
//commenting to find out what you're trying to do
//setting variable $affiliate to 530
$affiliate=530;

//In link pass as parameter affiliate
$myquery="?affiliate=".$affiliate."&";

//I've modified this coz its not the syntax to be used
//Question here is you've put $_GET what are you retrieving there's no param name to retrieve anything.
for ($i=1; $i&lt;=count($_GET); $i++)
{
//What on earth is that?? you're are redefining the variable to be something but what?
$myquery=$myquery.(($i)."=".($i)."";

//Modified
if ($i!=count($_GET))
{
//$myquery is being overiden again. to what??
$myquery=$myquery."&";
}
}
$Getpage="mysite.com/aff/".$myquery;
//REALLY STUCK HERE
?&gt;
</font id=code></pre id=code>
Replied 24 Jul 2006 17:27:37
24 Jul 2006 17:27:37 Panayiotis Savva replied:
Hi ;

I figured it out;

Hope this helps someone...


&lt;?
$affiliate=530;
$myquery="?affiliate=".$affiliate."&";
$i=0;
foreach (($_GET) as $key =&gt; $value)
{
$myquery=$myquery.($key."=".$value."";
$i=$i+1;
if (!(($i==count($_GET))))
{
$myquery=$myquery."&";
}
}
$requestingPage="mysite.com/aff/".$myquery ;
$file = fopen ($requestingPage, "r";
while (!feof ($file)) echo fgets ($file, 1024);
fclose($file);
?&gt;
Replied 24 Jul 2006 17:53:05
24 Jul 2006 17:53:05 Roddy Dairion replied:
OK. 2 things here either, its monday today and i can't understand anything or what you've done there is wrong. If its working ok but this script doesn't make sense to me. What is you script suppose to do?
Replied 24 Jul 2006 18:29:14
24 Jul 2006 18:29:14 Patrick Woldberg replied:
Shorter would be:

<pre id=code><font face=courier size=2 id=code>&lt;?
$affiliate=530;
$myquery="";
foreach (($_GET) as $key =&gt; $value)
$myquery=$myquery.$key."=".$value."&";
$requestingPage="mysite.com/aff/?".$myquery."affiliate=".$affiliate;
$file = fopen ($requestingPage, "r";
while (!feof ($file)) echo fgets ($file, 1024);
fclose($file);
?&gt;</font id=code></pre id=code>

The script outputs the content of the generated url

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------

Reply to this topic