Session Destroy
Moderator: General Moderators
Session Destroy
How can I make my page destroy a session when a user navigates away from that certain page?
Thanks,
Ross
Thanks,
Ross
Code: Select all
if (!eregi("yourfile.php", $_SERVER['SCRIPT_NAME'])) {
session_destroy();
}but you can modify to meet your need.
Its better to clear the entire thing:
The last line destroys the session from the cookie if present.
Code: Select all
session_unset();
$_SESSION = array();
session_destroy();
setcookie(session_name(),"",0,"/");supposing you would: just put that in a new .php file and include() or require() it on the pages you want to destroy the session.Ross2376 wrote:Wouldn't I have to apply that code to every page I don't want in the session?
If so, is there a way where I can have my script recognize when someone is coming from a "non-sessioned" page and destroy the open session there?
if you only have a few session vars set that you want to kill, you could always just unset() them.
I'm wanting to destroy a session (so it will reset itself) when a user navigates away from a single page. When they go back to the sessioned page, it will be reset. It's a thumb gallery. You can see it at AoD Media Page.
There is a counter that monitors what pics have already been displayed. It stores that in the session and then when the user clicks to next page, it just reloads same page only with updated counter (due to session). But when the user moves away from the page, I want the session to be destroyed so if they come back to the gallery, they wont be started in the middle of the gallery. Currently, the only session destroy happens at the end of the gallery.
By the way, those current thumbs are only test images. We will be using screenshots. Please advise on how to destroy the session when the user moves from the gallery page. I would prefer not to add session_destroy() to every page if I can just use something on the one gallery page.
Thanks
There is a counter that monitors what pics have already been displayed. It stores that in the session and then when the user clicks to next page, it just reloads same page only with updated counter (due to session). But when the user moves away from the page, I want the session to be destroyed so if they come back to the gallery, they wont be started in the middle of the gallery. Currently, the only session destroy happens at the end of the gallery.
By the way, those current thumbs are only test images. We will be using screenshots. Please advise on how to destroy the session when the user moves from the gallery page. I would prefer not to add session_destroy() to every page if I can just use something on the one gallery page.
Thanks