andr923 Posted July 5, 2007 Share Posted July 5, 2007 This is the code that I'm using to check if someone is logged in or not. This code is on every page because there is a login or logout button on every page. if (!isset($_SESSION['user'])){ echo '<a href="login.php">LOGIN</a>'; }else{ echo '<a href="logout.php">LOGOUT</a>'; } In the flow of my php document this checking if the user is logged in happens after the actual login or logout script. Because of this, I assumed that as soon as someone logs in, the code would reflect the change. For some reason, on the page that logs me in, the code still thinks that the session is not set yet and therefore I still see the login option. Same thing with logout. It takes for me to click on another page for the code to finally change. Any ideas what is going on? Thanks guys! Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 can we see the code or $_SESSION['user'] it should be initialize rigth before you go on other page Quote Link to comment Share on other sites More sharing options...
andr923 Posted July 5, 2007 Author Share Posted July 5, 2007 I fixed a problem with logging in. Now as soon as you log in, the code shows the logout link. It was an issue of making sure the right code happened in the right order (it was kind of confusing with the mixture of including files and functions). The LOGOUT however is still an issue. It is definitely not an issue with the order in which the code appears because right at the top of the page i have the session_destroy() command: <?php session_start(); $title = 'Logout'; // Logout Session session_destroy(); but for some reason, later on in the page i have this code: function logged() { if (!isset($_SESSION['user'])){ echo '<a href="login.php">LOGIN</a>'; }else{ echo '<a href="logout.php">LOGOUT</a>'; } } this code returns the 2nd option with the LOGOUT link. and yet again later I have: echo "<center><p>You have successfully logged out! {$_SESSION['user']}</p></center>" I put in the $_session['user'] variable just as a check to try and see if indeed the session info was still available. It seems like the session only gets destroyed after I leave the page. Quote Link to comment Share on other sites More sharing options...
andr923 Posted July 5, 2007 Author Share Posted July 5, 2007 I solved the problem, by immediately stating session_start(); again after I destroy the session. Is this what is necessary to clear all the session data? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 echo '<a href="logout.php?msg=destroy">LOGOUT</a>';// add query string look ? if (isset($GET['msg'])) { session_destroy(); } 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.