PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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;
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>";
?>
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.'))
You're in the middle of a quoted string: each \n will turn into a newline, like
if (confirm('There has been no activity for some time.
Click OK if you wish to continue your session,
or click Cancel to log out.
For your security if you are unable to respond to this message
within two minutes you will be logged out automatically.'))
started a timer in my page which counts the session time out 'time', warns the user before 5 minutes, if user doenst respond to that the page will be redirected to sessiontimeout.php.
i think the above code will also work, but not sure how to write embedded php n javascript.
i'm now trackin the session with javascript.
many thanks.