Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Passing entire URL as a Variable

7:46 am on Jul 20, 2006 (gmt 0)

New User

10+ Year Member

joined:Aug 13, 2003
votes: 0

I'm having trouble searching for this because I keep getting search results that have to do with passing variables through a URL. I have no problem doing that. I need to pass an entire URL to a PHP script like:


The problem I'm having is when someothersite.com has a long query string and some of the variables get truncated. My php knowledge is limited so I'm using

$url = $_GET['newsite'];

to grab the URL, but it doesn't work when the new URL has multiple variables. How do I keep the entire URL intact as it's passed to my script?

8:22 am on July 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 3, 2005
votes: 0

could you not replace all the ampersands in the variable newsite just before you send it and then convert i back after that? something like.

$newsite = [someothersite.com...]
$newsite = str_replace("&", "[MyAmp]", $newsite);

then on the page that receives just reverse it..
$newsite = $_GET["newsite"];
$newsite = str_replace("[MyAmp]", "&", $newsite);

8:36 am on July 20, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 6, 2004
votes: 0

You could also use urlencode()

$newsite = urlencode("http://www.someothersite.com/page.php?var1=1&var2=2");

In go.php
$newsite = $_GET["newsite"];
$newsite will be "http://www.someothersite.com/page.php?var1=1&var2=2" - no need to change.