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
Share on other sites

you could always do this:

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

I'm not sure how much good that will do, but if for any reason your session doesn't unset, it will be set to false.

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.