Forum Moderators: coopster

Message Too Old, No Replies

Newbie Question

What does this mean?

         

malcolmcroucher

5:42 pm on May 5, 2008 (gmt 0)

10+ Year Member



if(isset($_GET["n"])) $n=$_GET["n"];

in particluar .... isset ...

elitebomber

6:00 pm on May 5, 2008 (gmt 0)

10+ Year Member



It's checking to see if the variable $_GET["n"] has been set. In other words, does it exist? If the url was something like http://www.example.com/page.php?n=hamburger, then isset($_GET["n"]) will return true. If URL was just http://www.example.com/page.php then it would return false. So if it exists set $n to it's value.

coopster

6:02 pm on May 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



isset [php.net] determines whether or not a variable is set (available for use). The $_GET superglobal contains the variables passed in a query string. For example if you clicked a link to this page:
http://www.example.com/page.php?yourname=malcolmcroucher

... and in that page.php processing script you were to use isset to see if the variable was set you would do this:
if (isset($_GET['yourname'])) { 
print $_GET['yourname']; // prints "malcolmcroucher"
}

Thanks elitebomber :-)