justineaguas Posted November 10, 2009 Share Posted November 10, 2009 I am trying a simple login/logout for my website. It works well with checking if the username exists in the database to logging in. I used $_SESSION['username']=$myusername; However, when I log-out, then I go to a page with this code <?php session_start(); if($_SESSION['username']) //line5 echo "Welcome, ".$_SESSION['username']."!<br /><a href='logout.php'>Logout.</a>"; else die ("You must be logged in!"); ?> It gives me an error. It says Notice: Undefined index: username in C:\wamp\www\datbas\member.php on line 5 I just want to know how to fix this. Thank you. Quote Link to comment Share on other sites More sharing options...
cags Posted November 10, 2009 Share Posted November 10, 2009 Notices are extremely low level errors. It's telling you that there isn't an item in the $_SESSION array called 'username' and you are trying to check it's value. The solution is to first check it exists before checking it's value. session_start(); if(isset($_SESSION['username'])) //line5 echo "Welcome, ".$_SESSION['username']."!<br /><a href='logout.php'>Logout.</a>"; else die ("You must be logged in!"); Quote Link to comment Share on other sites More sharing options...
justineaguas Posted November 10, 2009 Author Share Posted November 10, 2009 Oh yeaah. It is now fixed. Thanksss. I now know how to use isset. Thanks a lot Quote Link to comment 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.