Ok, I read this post and someone suggest using this code to check if user left page:
if($_SERVER['REQUEST_URI'] !== 'page_with_session.php'){
session_destroy(); // Kill session for all pages but page_with_session.php
}
Now can someone please explain how REQUEST_URI works cause I can’t seem to find it in the PHP manual, or can someone suggest another way to check when a user has left a page.
Please note I can’t use Javascript for this project.
With that code you can only tell when a user changes to another page on your server. If he leaves to another website, or closes the tab/browser, this won’t work. Use javascript instead or use a session timeout.
REQUEST_URI is the URI of the current request, so if a user changes to another page on your server, you can check that it’s not the “session page” and destroy the session. this will only work if you don’t use rewrite or similar techniques.