Forum Moderators: coopster

Message Too Old, No Replies

Ampersand in a Variable

         

Ian Cunningham

7:46 pm on Jan 1, 2004 (gmt 0)

10+ Year Member



I have a file (test.php) which I call from the browser, for example:

test.php?url=http://www.example.com/abc.php?a=1&b=2

in the test.php file I have the code:

echo "$url";

But, I only see "http://www.example.com/abc.php?a=1" printed, and everything after the ampersand is missed out. How would I use URLEncode to get past this (if that is what is needed)?

travelbuff

9:24 pm on Jan 1, 2004 (gmt 0)

10+ Year Member



I bet if you do an echo $b you would get a value of 2. The problem is that PHP thinks you are defining 2 variables - url & b. I don't know how to fix it other than echo $url.$b or rebuilding the variable $url=$url.$b .

Mark

paladin

1:30 am on Jan 2, 2004 (gmt 0)

10+ Year Member



how about something like:
$_ENV['QUERY_STRING']

Xuefer

3:07 am on Jan 2, 2004 (gmt 0)

10+ Year Member



"test.php?url=" . urlencode("http://www.example.com/abc.php?a=1&b=2")

-> $_GET['url']

test.php?url=urlencode("http://www.example.com/abc.php?a=1&b=2

-> substr($_SERVER['QUERY_STRING'], 4)

httpwebwitch

8:58 pm on Jan 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



urlencode() your variables before tacking them on your querystring. You shouldn't put more than one "?" in your URL, it's bad form. Encoding the querystring variables will change your "?" and "&" characters into non-threatening strings that will remain intact until you "GET" them back.

g1smd

10:57 pm on Jan 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need the & to be coded as & in order for the page to be valid as an HTML document anyway.