Skip to main content
Inspiring
July 1, 2006
Question

isset($_SERVER['QUERY_STRING']) always returns true?

  • July 1, 2006
  • 2 replies
  • 3278 views
hi:

i have this code wich always is returning true for
isset($_SERVER['QUERY_STRING']) even when calling the page without
passing vars through the url

$thisURL = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$qs = 1;
$thisURL .= "?".$_SERVER['QUERY_STRING'];
}

for example, typing in the browser:
http://mac.local/~admin/.../home.php

echoes:
PHP_SELF: /~admin/.../home.php
QUERY_STRING:
$thisURL: /~admin/.../home.php?

do i need to unset $_SERVER['QUERY_STRING']???

OSX 10.4, PHP 5.0.4

tia,

jdoe
This topic has been closed for replies.

2 replies

Inspiring
July 3, 2006
gareth wrote:
> I don't like using isset(),

isset() tells you whether the variable has been defined - nothing more,
nothing less.

The correct way to test without generating any errors or notices is this:

if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Inspiring
July 3, 2006
I don't like using isset(), had various problems with it on different
systems.

Try changing isset() to strlen() ie

if(strlen($_SERVER['QUERY_STRING']) > 0){

}

And see if that works, will only be true if there are actually some
characters contained in $_SERVER['QUERY_STRING']

Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.