Jump to content

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

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.