I Am Chris Posted August 3, 2008 Share Posted August 3, 2008 ok so i have this code <?php session_start(); if ($_SESSION['logged'] == 1) // User Logged In echo ("<a href=\"logout.php\">Logout</a>"); else echo "<a href=\"register.php\">Register</a>" . "<br />" . "<a href=\"login.php\">Login</a>"; ?> It's all working well. However, the logout page isn't working this is my code for logout.php <?php session_unset(); session_unset(); session_destroy(); $_SESSION = array(); header("Location: index.php"); // Goes back to login. ?> for some reason, it isn't deleting my session and i stay logged in is there any obveous reason why? it makes no sense to me. please help Link to comment https://forums.phpfreaks.com/topic/117910-solved-need-help-destroying-sessions/ Share on other sites More sharing options...
jonsjava Posted August 3, 2008 Share Posted August 3, 2008 in order to destroy a session, you must first initialize the session. <?php session_start(); session_unset(); session_destroy(); $_SESSION = array(); header("Location: index.php"); // Goes back to login. ?> Link to comment https://forums.phpfreaks.com/topic/117910-solved-need-help-destroying-sessions/#findComment-606506 Share on other sites More sharing options...
I Am Chris Posted August 3, 2008 Author Share Posted August 3, 2008 hmm, works great. ty. i only spent like all day on this. Why exactly do I have to start the session first? obveously it works, but whats the logic behind it? is there any good knowledge base on sessions? I don't think i understand them as well as i'd like too. Link to comment https://forums.phpfreaks.com/topic/117910-solved-need-help-destroying-sessions/#findComment-606509 Share on other sites More sharing options...
jonsjava Posted August 3, 2008 Share Posted August 3, 2008 session_start(); locates the associated session. Without knowing which session you are working with, it's impossible to destroy it. Link to comment https://forums.phpfreaks.com/topic/117910-solved-need-help-destroying-sessions/#findComment-606512 Share on other sites More sharing options...
I Am Chris Posted August 3, 2008 Author Share Posted August 3, 2008 ok ty Link to comment https://forums.phpfreaks.com/topic/117910-solved-need-help-destroying-sessions/#findComment-606545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.