javascript in PHP to warn session about to expire..
Posted: Fri Oct 31, 2008 10:45 am
Hii,
i'm using javascript code in php to warn a user that his session is about to expire in x minutes,
for that i tried a script like this, but it is not getting executed.
herez the php script;
herez my html code,
why is the script not bein executed? please help me ..
thanks n regards.
i'm using javascript code in php to warn a user that his session is about to expire in x minutes,
for that i tried a script like this, but it is not getting executed.
herez the php script;
Code: Select all
echo "<SCRIPT LANGUAGE='JAVASCRIPT'>
var a, pageTimer; //declare var
function startClock()
{
pageTimer = 0; //start at 0
a = window.setInterval('tick()',60000); //run func tick every minute.... (60 sec x 1000 ms = 1min)
}
function tick()
{
pageTimer++; //increment timer
if (pageTimer == 28) {warnuser()}; //if 28 min without activity
}
function warnuser()
{
if (confirm('There has been no activity for some time.\nClick OK if you wish to continue your session,\nor click Cancel to log out.\nFor your security if you are unable to respond to this message\nwithin two minutes you will be logged out automatically.'))
{
// restart session
session_start();
}
else
{
//end session force user to login page
include 'sessiontimeout.php';
}
}
</SCRIPT>";
?>
Code: Select all
<body BGCOLOR="#F8F5EF" class="PSPAGE" onload="startClock();">thanks n regards.