在包含带有'&'符号的值的变量中传递URL

I Want to pass Url inside one variable, this variable contains url with values.
for example:

$addr = "http://".$_SERVER['SERVER_NAME']."/".$_SERVER['REQUEST_URI']."";
echo $addr;

this step will give me http://localhost/index.php?page=3&var1=A&var2=B
When i passing this $addr var to another page, and echo it, i get only `http://localhost/index.php?page=3
its look like when there is & sign its gone. what should i do? there is way to pass this variable and echo the whole var?
thanks.

You will want to urlencode them. A quick Google search shows me that simply replacing & with %26 is enough.

Try to use $_SERVER['QUERY_STRING'] to get at least all the values after question mark.

You can use $_SERVER['HTTP_REFERER'] (but be careful as it's not 100% reliable).

Another option would be to add it to the URL.

$addr = "http://".$_SERVER['SERVER_NAME']."/".$_SERVER['REQUEST_URI']."";
$addr = urlencode($addr);
$yourUrl = 'http://wwww.google.com?var1=4'; // some url
header("Location:{$yourUrl}&from={$addr}");

That's about it.