Welcome to WebmasterWorld Guest from 54.80.185.137

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Why would $ SERVER['QUERY STRING'] not be working?

     
8:52 am on Jun 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 25, 2003
posts:2528
votes: 0


If I have the following script at http://www.example.com/js/script.php:

$myUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$queryString = $_SERVER['QUERY_STRING'];
echo "total url = $myUrl?$queryString";

and I type:

http://www.example.com/js/script.php?show=http://www.google.co.uk

into my web browser I was expecting http://www.example.com/js/script.php?show=http://www.google.co.uk to appear on the page, but it doesn't - all I get is:

http://www.example.com/js/script.php?

Where have I gone wrong?

Thanks
Mike

9:18 am on June 6, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


Off the top of my head, perhaps it's necessary to separate the variables from the question mark, i.e.

echo 'total url = '.$myUrl.'?'.$queryString;
9:26 am on June 6, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Aug 9, 2005
posts:240
votes: 0


You could also try...

$myUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$queryString = "";
foreach ($_GET as $k => $v) {
$queryString .= "&".$k."=".$v;
}
if (strlen($queryString) > 1) $queryString = "?" . substr($queryString, 1);
echo 'total url = '.$myUrl . $queryString;

[edited by: FiRe at 9:27 am (utc) on June 6, 2008]

9:36 am on June 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 25, 2003
posts:2528
votes: 0


Nevermind! My own forgetfulness. As a spam prevention I'd put a query string destroyer in my htaccess file some time ago. You need to list the folders that it should not affect and I was working in one that wasn't listed!

I'm annoyed at that, I've spent over an hour wondering "what on earth?" and trying everything thinking my server might be broken. Damn spammers, have to waste my time putting up code to stop them and now waste my time because I can't keep track of all the spam prevention measures I've had to install!

Thanks anyway guys.