Jump to content

Need isset()?


doubledee

Recommended Posts

  Quote

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
https://forums.phpfreaks.com/topic/254557-need-isset/#findComment-1305330
Share on other sites

  Quote

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
https://forums.phpfreaks.com/topic/254557-need-isset/#findComment-1305334
Share on other sites

  Quote

  Quote

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
https://forums.phpfreaks.com/topic/254557-need-isset/#findComment-1305339
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.