iStriide Posted August 14, 2011 Share Posted August 14, 2011 I have this bit of code and when the user is logged out it shows an error and it messes with the way my site looks. The error is this: Undefined index: user in C:\xampp\htdocs\halobattles\index.php on line 90 Here's is an example of how my code looks: <?php session_start(); if($_SESSION['user']){ echo "Logged In"; }else{ echo "Normal"; } ?> I want the error to go away when people are logged out. Quote Link to comment https://forums.phpfreaks.com/topic/244793-_sessionuser-undefined-problem/ Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 Perhaps check to see if the array key exists before using it? isset() is what you want. Alternately, you can use empty() which doesn't throw a notice on undefined variables or non-existent keys. Quote Link to comment https://forums.phpfreaks.com/topic/244793-_sessionuser-undefined-problem/#findComment-1257402 Share on other sites More sharing options...
iStriide Posted August 14, 2011 Author Share Posted August 14, 2011 Would I just put "empty()" on the top of the code? Quote Link to comment https://forums.phpfreaks.com/topic/244793-_sessionuser-undefined-problem/#findComment-1257416 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 Next time, please check the manual before asking. http://php.net/empty if( empty($_SESSION['user']) === FALSE ) { echo 'logged in'; } else { echo 'not logged in'; } Quote Link to comment https://forums.phpfreaks.com/topic/244793-_sessionuser-undefined-problem/#findComment-1257417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.