By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

session destroy for while user stay in one page without any action

oranoos3000
100+
P: 107
hi
I 'd like to session destroy when that user for 1 hours dont dont press any key or scroll page and dont go to another or in other words stay in one page for a alot of time


thanks alot
Jun 6 '10 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hey.

If you want to detect when a user presses a key or scrolls the page, and destroy a session based on that, you will need to use JavaScript and AJAX to trigger the PHP code that actually destroys it.

To do what you are asking, I would do the following:
  • Set PHP up so that the session times out after an hour. See this article for details on how to do that.
  • Create a PHP ping page that simply "refreshes" the session timeout. It wouldn't have to do anything other than start the session and update whichever timeout method you use (if any).
  • Have the JavaScript code monitor the user input. When the user is active, send periodic AJAX requests to the PHP ping page. If he becomes inactive, stop sending the AJAX requests.
The result of this would be that while the user is actively working on a page of your site, his session would remain alive, even though he never really requests anything from the server.
Jun 7 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.