Jump to content

Recommended Posts

:-\

I'm using a logout script, but when I select the back browser button I'm still logged in.  Here is the code.....

session_start();

if(!isset($_REQUEST['logmeout'])){
    echo "<center>Are you sure you want to logout?</center><br />";
    echo "<center><a href=logout.php?logmeout=true>Yes</a> |
    <a href=javascript:history.back()>No</a>";
} else {
session_destroy();
}
?>
Link to comment
https://forums.phpfreaks.com/topic/15653-need-help-wsession_destroy/
Share on other sites

Its a bit of a hack, but maby set it to something that isnt going to be valid. EG  i use "in" and "out" for my logged in session, and it just gets set to "als;dfjnasf" if they are logged out.
and when i validate if they are logged in, obviousally "asdfaSDF" isnt a valid entry, so it rejects them.
Might help.
Cheers,
Nathan
when wanting to end a session it is essential that you unset any session variables you have previously set, eg,

session_start();

if(!isset($_REQUEST['logmeout'])){
    echo "<center>Are you sure you want to logout?</center>";
    echo "<center><a href=logout.php?logmeout=true>Yes[/url] |
    <a href=javascript:history.back()>No[/url]";
} else {
[color=green]unset($_SESSION['session_var_here']);[/color]
session_destroy();
}
?>

so you need to use unset(); on any session vars before you call session_destroy() or you will get the the problem you detailed
Also read this as a refrence ok.


session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
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.