Page 1 of 1

Testing the contents of $_GET - the right way

Posted: Tue Sep 16, 2003 10:47 am
by maniac9
I've been searching for the correct, (and maybe most efficient) way of testing to see if a certain named value exists in the GET variables. Actually, I just need the quickest way to test whether or not a query string was actually supplied.

Posted: Tue Sep 16, 2003 10:50 am
by JayBird

Code: Select all

if (isset($_GET['some_variable'])) {
   // do something
}
Mark

Posted: Tue Sep 16, 2003 10:55 am
by SantaGhost
for troubleshooting:

Code: Select all

<?php
print_r($_GET);
?>

Posted: Tue Sep 16, 2003 11:05 am
by JAM
I would like to mention this solution also, as a empty string doesn't really need to be correct. Have in mind that the int 0 will also make empty() TRUE.

Code: Select all

if (!empty($_GET['some_variable'])) {
   // do something
}

Posted: Tue Sep 16, 2003 12:13 pm
by McGruff
If you aren't checking for a particular element but just want to check if any GET vars were passed at all:

Code: Select all

<?php
if(isset($_SERVER['QUERY_STRING']))
?>