i need to perform an action when the user exits from the webpage, i figured i'd use timeout to do so, it works, but only if i refresh/reload the page, which is not what i want, i need it to work automatically, if the user is inactive for say, 5 minutes, i need a certain file, belonging to that user to get destroyed. i did the following test first to check if the timeout would work:
<?php
session_start();
//set timeout
$inactive=60;
//check to see if timeout is set
if(isset($_SESSION['timeout'])){
$session_life= time() - $_SESSION['timeout'];
if($session_life > $inactive)
{session_destroy();
echo "new message<br>";
}
}
$_SESSION['timeout']= time();
echo "after one minute,a new message should be added.";
?>
it works only if i reload/refresh the page, how would i make it automatically execute the command after inactivity within the said time frame?thanks in advance.