Alan Edwardes

Using PHP isset To Detect An Empty GET Request

Here's something I learnt a while back, about how to detect if there is a ?foo after the page URL, even if that GET request is empty (without the =bar) bit. Try it on my "Random Post" button, you will find it adds a ?r after the post URL you are sent to, so the page knows to add an ID that makes the button highlighted.

So, to detect it:

if (isset($_GET['foo'])) echo('Yeah, foo is set');

This would work on something like http://www.example.com/index.php?foo, and avoids an unnecessary ?foo=yes or something to indicate that foo is true. Neat and tidy :-)

1 Comment

Sarthak's Gravatar
1

well the if condition based on isset($_GET['var']) works fine with echo etc... but the problem arises when u try to use the get variable inside the if condition in something like.... if(isset($_GET['var'])) { $var2=$_GET['var']; } else { $var2=$var3; } searched a lot on google and found many people having this problem ..

Add a Comment

06th of June 2008 at 2:09 PM

3 years, 11 months ago

written by Alan Edwardes.

100 words

1 comment so far

feed for comments on this post

rand: Portal 2 and the Valve ...

next: Windows Vista - The Ready ...

prev: Firefox Auto Download Security Flaw

share:FacebookTwitterRedditdiggStumbleUpondeliciousHacker NewsLinkedIn

add a comment

© 2006 – 2012 Alan Edwardes / code on github
Top