Page 1 of 1

Session Destroy

Posted: Mon May 30, 2005 12:13 am
by Ross2376
How can I make my page destroy a session when a user navigates away from that certain page?


Thanks,

Ross

Posted: Mon May 30, 2005 2:19 am
by hongco

Code: Select all

if (!eregi("yourfile.php", $_SERVER['SCRIPT_NAME'])) { 
   session_destroy();
}
this supposes that you move to another page with different file.
but you can modify to meet your need.

Posted: Mon May 30, 2005 3:12 am
by anjanesh
Its better to clear the entire thing:

Code: Select all

session_unset();
$_SESSION = array();
session_destroy();
setcookie(session_name(),"",0,"/");
The last line destroys the session from the cookie if present.

Posted: Mon May 30, 2005 3:21 am
by hongco
thanks! I should do this :)

Posted: Mon May 30, 2005 4:43 am
by Ross2376
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?

Posted: Wed Jun 01, 2005 12:40 am
by Ross2376
Um hello?

Posted: Wed Jun 01, 2005 1:00 am
by Burrito
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?
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.

if you only have a few session vars set that you want to kill, you could always just unset() them.

Posted: Wed Jun 01, 2005 1:08 am
by Ross2376
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

Posted: Wed Jun 01, 2005 9:24 am
by Burrito
unset a session var you could. Put the visited pictures in an array an serialize it I would. Save the serialized array in a session and check against it on pages with more pictures you should.

the session var on pages with no pictures you should unset.

Posted: Wed Jun 01, 2005 2:15 pm
by Ross2376
No offense, but you sound like yoda. I have no clue what you are talking about. Can you give me an example?

Posted: Wed Jun 01, 2005 2:18 pm
by shiznatix
it was yoda speak night of course!

look up serialize and unset on php.net