Jump to content

Need isset()?


doubledee

Recommended Posts

Yes but as you know adding isset() will stop undefined index errors and the second check could be any number of things related to the session like $_SESSION['loggedIn'] == "Banned".  But you are right, if it's TRUE then it's SET.

 

So it sounds like I should usually have an isset() for the undefined index issue, right?

 

 

Debbie

Link to comment
Share on other sites

So it sounds like I should usually have an isset() for the undefined index issue, right?

 

Anytime you can't guarantee that a variable/index exists (usually with any of the $_* vars that comes in from the request) you should use isset() to prevent the notice error.

 

Sometimes, just checking whether it is set is enough.  If you set $_SESSION['loggedin'] when the user does their login, then unset it or destroy the session data on logout, then the mere fact that $_SESSION['loggedin'] exists is enough:

 

if (isset($_SESSION['loggedin'])){
...
}

 

 

Link to comment
Share on other sites

So it sounds like I should usually have an isset() for the undefined index issue, right?

 

Anytime you can't guarantee that a variable/index exists (usually with any of the $_* vars that comes in from the request) you should use isset() to prevent the notice error.

 

Sometimes, just checking whether it is set is enough.  If you set $_SESSION['loggedin'] when the user does their login, then unset it or destroy the session data on logout, then the mere fact that $_SESSION['loggedin'] exists is enough:

 

if (isset($_SESSION['loggedin'])){
...
}

 

Good points.

 

Thanks,

 

 

Debbie

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.