ShoeLace1291 Posted August 28, 2011 Share Posted August 28, 2011 So, for the past couple of years or so I've been using CodeIgniter to develop my PHP applications... which may have been a mistake. As of late, I've been trying to get away from frameworks and am developing an application purely on my own. I never had this problem with CI, but whenever I try to determine if a variable/index has been defined, I get an error. For example, if I use an if statement to see if a session index called "mid" was defined, I get a PHP error saying that it's undefined. Is there any way to get around this? <?php if($_SESSION['mid']){ echo $inbox; } else { echo 'Your not logged in!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245850-undefined-index-problems/ Share on other sites More sharing options...
Psycho Posted August 28, 2011 Share Posted August 28, 2011 When you try to reference a variable that does not exist you may get a warning message depending upon the error level set on the server. The correct way to check if a variable has been set or not is . . . wait for it . . . isset()! if(isset($_SESSION['mid'])){ echo $inbox; } else { echo 'Your not logged in!'; } However, if you were really wanting to check if the value of $_SESSION['mid'] is TRUE (when it is set), then you might need to do this: if(isset($_SESSION['mid']) && $_SESSION['mid']){ Quote Link to comment https://forums.phpfreaks.com/topic/245850-undefined-index-problems/#findComment-1262735 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.