Jump to content

Session doesn't unset...


darkywarkey

Recommended Posts

I've created a user authentication session control which is working fine. The problem I'm having is when I logout a registered user, the session appears to be unset on the first load of the page but any subsequent page loads show the user that was just logged out active again. Using php 5.2.6 and the logout script is as follows...

 

<?php session_start();
unset($_SESSION['valid_user']);
session_destroy();
?>

 

Any ideas what could cause this?  ??? ???

Link to comment
https://forums.phpfreaks.com/topic/107521-session-doesnt-unset/
Share on other sites

Then I'm not using them. I wasn't sure if there was something in the php.ini that could be auto setting them. Not familiar with cookies either. Any other ideas?

 

By default, PHP sessions do create cookies.  This is actually a *good thing* IMNSHO.

 

Pulled directly from the PHP manual ---

 

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();
?>

Link to comment
https://forums.phpfreaks.com/topic/107521-session-doesnt-unset/#findComment-551182
Share on other sites

try this:

<?php
session_start();
session_unset();
session_destroy();
header("location:index.php");
exit();
?>

 

Didn't work...

 

No code automatically loading the session. It's user authentication, so they have to login with a username/password, which then sets the session variable.

 

After logging out and it apparently working (the script shows a login field again, which is only shown when the session variable is unset), I try clicking the home page again and it acts as if I never logged out, showing the previous users information once again.

Link to comment
https://forums.phpfreaks.com/topic/107521-session-doesnt-unset/#findComment-551185
Share on other sites

Figured it out!

 

Weird as this is... it was the way the various pages were being linked, as in their url's. Some links I coded without the 'www.' in front of the domain name, and some were. I guess the sessions were being kept seperate between the two url variations. Good to know.

 

Guess that goes to show you should always be consistent in coding standards. :D

Link to comment
https://forums.phpfreaks.com/topic/107521-session-doesnt-unset/#findComment-551408
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.