Right now, when the user comes to a page a session is started; that’s working fine. But how can I detect when a user leaves that page? I need it so that when the user leaves the page, the session is destroyed.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You wouldn’t be able to use PHP to detect the user leaving the page, but you can send an ajax request via javascript on the unload event to destroy that users session.
Related post: Can you fire an event in JavaScript before the user closes the window?