Jump to content

resting variables?


amg182

Recommended Posts

Hi guys.

 

I need to destroy a session when a user leaves a particular page. I tried using session_destroy() at the end of the page but its not possible, because my page has pagination. i.e. abc.php?page=1 etc...

 

So, I need to destroy a session when a user leaves abc.php page.

 

Thanks in advance

Aidan

Link to comment
https://forums.phpfreaks.com/topic/253674-resting-variables/
Share on other sites

You may try to do the next:

1. Start session at any page.

2. Every time write into the session the page name.

3. Before writing (p.2) check: if current page name and recorded page name are different - you just leaved the previous page. Then you may delete some session variables or close and destroy session - as you wish.

4. An of course :) if current and recorded names are equal it means that you stay at the same page.

Link to comment
https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300457
Share on other sites

You can't do anything when a user LEAVES a page, only when the user VISITS a page.

 

The best way to do it is what Sergei said:  Whenever the user hits that page, put a flag in the session.  Then, on every other page (or in the central place where you call session_start), if that flag is set and they're not on the flagged page, that means they left the page.  Kill the session.

Link to comment
https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300466
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.