带有警告的PHP / Javascript会话超时

带有警告的PHP / Javascript会话超时

问题描述:

Does anyone know where I can read a tutorial on, or know how to create a Javascript-based session timeout that has a warning built in, and optionally these features:

  • user activity resets the timer
  • interacts with database (last seen on, etc.)
  • if inactive, it will log out users (by redirecting to a logout.php page)
  • before it logs users out, it will display a popup message that asks if they want to continue

Unfortunately, I don't know too much about Javascript.

有谁知道我可以在哪里阅读教程,或者知道如何创建基于Javascript的会话超时 内置警告,以及可选的这些功能: p>

  • 用户活动重置计时器 li>
  • 与数据库交互(最后一次见到,等等) ) li>
  • 如果不活动,它将注销用户(通过重定向到logout.php page) li>
  • ,然后再将用户注销,它将显示一条弹出消息 要求 他们想要继续 li> ul>

    不幸的是,我对Javascript知之甚少。 p> div>

I don't know how your website is done, but if done right, you should have a log in session and some sort of back end control system that denies any action if the previous action was made X minutes/hours ago and automatically expires the user. If you want to implement some client side code, you should have a javascript timer that alerts the user when expire time is about to be complete and you can also redirect the user to the homepage or log in page after the expire time is reached. This way all security features are on the back end and the javascript only works as a display measure for the display behavior.

UPDATE:

setInterval(function(){alert("Hey, your session is ending")},360000);

setInterval(function(){
    redirect();
},720000);

function redirect(){
    document.location = "../logout.php"
}

UPDATE2:

setInterval(function(){
    logout();
},600000);

function logout(){
    if(confirm('Logout?'))
        redirect();
    else
        alert('OK! keeping you logged in')
}

function redirect(){
    document.location = "../logout.php"
}

Every page with this code will ask after 10 minutes if the user wants to logout. This means your session cannot expire by itself, you must leave the control to the user