php - Automatic Log-off

615

How do i create a script that will log out the user after 10 minutes of inactivity.

Thanks.

668

Answer

Solution:

For PHP, include this code in commonfile

if(isset($_SESSION['last_activetime'])){    
   if(time() - $_SESSION['last_activetime'] > 600) { 
        header("location:logout.php");
        exit;
   }    
}
$_SESSION['last_activetime'] = time(); // when user open page time store in session
961

Answer

Solution:

Each time the user does something, update a timestamp in a table somewhere for that user. Have a cron job on the server that looks in that table, and logs out anyone that is logged in but haven't had his timestamp updated in ten minutes.

People are also looking for solutions to the problem: Query XML with variable using PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.