1

When a user leaves my website, and right before the session times out I would like to be able to run a script that send me an email.

I have looked into a few different ways, for example, using JavaScript. However I found these methods are unreliable.

I came acrosssession_set_save_handler but I am not sure if this is what should use or if there is a better method of doing this.

Thanks for any help. Also a tutorial on how I can do this would be awesome.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
EzGoing
  • 23
  • 5
  • You'll need to check two things. 1. Session expire (session could expire while on the page). 2. Page leaving. You'll need to do this with JS/ajax. – chris85 Mar 20 '15 at 23:17
  • Good explaination of session_set_save_handler: http://stackoverflow.com/questions/8416159/php-run-a-script-when-a-session-expires – LinkBerest Mar 20 '15 at 23:19
  • How would be the best way using js/ajax? everything i have read required using on window close, the issue being sometimes it doesn’t have enough time to run before closing. or am i missing something? – EzGoing Mar 20 '15 at 23:21
  • Not familiar with window close. Check out these events, https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload, http://www.w3schools.com/jsref/event_onunload.asp. The browsers fire these events so you don't have to worry about it being too soon. – chris85 Mar 20 '15 at 23:24
  • Sorry I meant to say on onunload. Not window close. The issue with onunload is that will call my email function every time the page re-loads. Not just when they leave. – EzGoing Mar 20 '15 at 23:30

0 Answers0