It is an essential professional approach to implement all necessary checks while developing a web based application. Sometimes it is necessary to check user’s inactivity on application because may be user forget to log out or their might be some other reasons too for his inactivity for example cialis canada. So you should have to check if user is inactive for certain period of time, you can log him out and destroy session. Your this approach build user’s trust in your development skills and definitely he will feel secure while using your website or application. So here is a quick way to check user’s inactivity and then log him out and destroy application.

First of all we have to add a single line of code in our login page to add the time of login in session.

$_SESSION['last_acted_on'] = time();

Then add following code in every page of your application to check user’s inactivity.

if( isset($_SESSION['last_acted_on']) && (time() - $_SESSION['last_acted_on'] > 30*60) ){
 session_unset(); // unset $_SESSION variable for the run-time
 session_destroy(); // destroy session data in storage
 header('Location: index.php');
 $_SESSION['last_acted_on'] = time();

What will this code do?

First it take time from session that we have stored recently in above line, then it will take current time and subtract it from current time. If  the result is greater than 30 minutes (you can change as your wish) it will log out the user and redirect him to our login page and if the result is less than 30 minutes it will store new time in session that is our current time.

[sdm_download id=”43″ fancy=”1″]


  1. in the download is the code:

    if( isset($_SESSION[‘last_acted_on’]) && (time() – $_SESSION[‘last_acted_on’] > 60*10) ){

    in the tut is

    if( isset($_SESSION[‘last_acted_on’]) && (time() – $_SESSION[‘last_acted_on’] > 30*60) ){

    what is wrong?

Leave a Reply