Forum Moderators: coopster

Message Too Old, No Replies

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

         

internetheaven

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

WebmasterWorld Senior Member 10+ Year Member



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

barns101

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

10+ Year Member



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;

FiRe

9:26 am on Jun 6, 2008 (gmt 0)

10+ Year Member



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]

internetheaven

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

WebmasterWorld Senior Member 10+ Year Member



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.