Skip to content
Advertisement

PHP – make session expire after X minutes

i am using the following technique…

From the login.php the form posts to the page check.php where i do this

JavaScript

and on loggedin.php page the first thing i do is

JavaScript

but once logged in when i directly type the url localhostmyProjectloggedin.php it displays the page…which makes perfect sense because the session has started

what i want to implement is

  • The direct URL session works for 10 minutes after that the session is terminatedexpiredtimed out and then use must login again and may get the same session id but after 10 minutes use won’t be able to browse with the same session

WHAT DO I NEED TO DO OR LEARN

Advertisement

Answer

Store a timestamp in the session:

JavaScript

Check if the timestamp is within the allowed time window (600 seconds is 10 minutes):

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement