Testing the contents of $_GET - the right way
Moderator: General Moderators
Testing the contents of $_GET - the right way
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.
Code: Select all
if (isset($_GET['some_variable'])) {
// do something
}- SantaGhost
- Forum Commoner
- Posts: 41
- Joined: Mon Sep 15, 2003 11:54 am
for troubleshooting:
Code: Select all
<?php
print_r($_GET);
?>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
}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']))
?>