Reputation: 21136
If I were to call:
www.*.com?hello
if($_GET["hello"]){
}
It will always return false because ?hello variable needs to be set as something...
Is there a way to get the ? part without setting the variable to anythign before hand?
Upvotes: 2
Views: 294
Reputation: 5108
if(!empty($_GET["hello"]))
{
}
Instead of checking for both isset and $_GET != "".
Upvotes: 0
Reputation: 3539
You can check if variable is set like this:
if(isset($_GET["hello"])){
}
sometimes key_exists()
is better because if $_GET["hello"] == null
you can get false
if (key_exists("hello", $_GET)) {
}
Upvotes: 6
Reputation: 2181
The usual way is to check it like:
if(isset($_GET["hello"]) && $_GET["hello"] != ""){
//code
}
Upvotes: 0
Reputation: 116110
Use array_key_exists:
if (array_key_exists("hello", $_GET)) {
}
Please read this for a difference between isset and array_key_exists.
Upvotes: 1
Reputation: 10529
$_GET["hello"]
is falsy, check if it's set at all
if (isset($_GET["hello"])) {
//do stuff
}
Upvotes: 1