amg182 Posted December 22, 2011 Share Posted December 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253674-resting-variables/ Share on other sites More sharing options...
AyKay47 Posted December 22, 2011 Share Posted December 22, 2011 in order to completely erase the session, you will need to use a combination of session_destroy() and unset() on the session variables that you want to remove. this should help you. Quote Link to comment https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300456 Share on other sites More sharing options...
SergeiSS Posted December 22, 2011 Share Posted December 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300457 Share on other sites More sharing options...
ManiacDan Posted December 22, 2011 Share Posted December 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300466 Share on other sites More sharing options...
amg182 Posted December 22, 2011 Author Share Posted December 22, 2011 Cheers guys, that worked a treat! Merry Xmas to you all. Aidan Quote Link to comment https://forums.phpfreaks.com/topic/253674-resting-variables/#findComment-1300468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.