Welcome to WebmasterWorld Guest from 54.167.86.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

isset - how do you explain everything it does?

     

whatson

8:02 pm on Sep 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I kind of get isset function, but not entirely.
I understand it is mainly used with if statements.
Is it just for submitting forms? And what is the difference for isset with GET and POST?

If I use it for GET
e.g. if(isset($_GET['page']))
Does this check the url to see if there is a value for page?

And for POST, does it just mean, if the form submit button is clicked?

londrum

8:09 pm on Sep 15, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



it's possible to set (or overwrite) a GET variable or a POST variable in your script, just be writing
$_GET['page'] = 'blah';

$_POST['page'] = 'blah';


so they don't have to come from a URL or a form (although they usually do).

i think isset just checks whether a variable exists. it doesn't care where it came from.

whatson

8:17 pm on Sep 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh, so it just checks if a variable exists, that makes sense.

g1smd

9:21 pm on Sep 15, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



IF "IS SET" (binary answer: yes/no) THEN...

MinosTheNinth

10:04 am on Sep 17, 2012 (gmt 0)



In case testing $_GET['page'] it only test that variable exists (as answered above). But it does not test if variable has value. From isset point of view there is no difference between ?page and ?page=index

If you want to test that variable has some data, you can use empty() - [php.net...]

jadebox

9:56 pm on Sep 17, 2012 (gmt 0)

10+ Year Member



Isset returns false if the specified variable (or array element) has not been defined or if it has been defined but was assigned a value of null.

Isset is not a function. It is a "language construct." It sounds like I'm being pendantic to point it out, but it is important to know because you can't, for example, reference it as a variable function or pass it to a method expecting a function.

-- Roger
 

Featured Threads

Hot Threads This Week

Hot Threads This Month