Reputation: 27
I have the code
if(isIdleTimeExceeded())
{
logout();
header("Location:".$baseurl."index.php");
exit();
}
In IdleTimeExceeded I am checking the time.
I want to get jQuery alert box after session expires.
Upvotes: 0
Views: 1225
Reputation: 14173
The code you posted is PHP code. But after the page has been sent to the client, you no longer have access to php functions. If idle time means the user hasn't switch page in x amount of seconds, then you just need javascript.
<script>
//the function IdleToLong will be called after 30seconds.
//This means if the page reloads, it starts over.
setTimeout(IdleToLong, 30 * 1000); // 30 seconds
function IdleToLong() {
alert('Move your ass');
//If you also need to logout in PHP then you must notify the server that a user has been idle to long.
$.get('logout.php?reason=idle').complete(function() {
window.location.href = '/';
});
}
</script>
Upvotes: 2
Reputation: 942
To create Alert using javascript
echo '<script type="text/javascript">alert("Logged out!!");</script>';
Upvotes: 0