带有警告的PHP / Javascript会话超时 [英] PHP/Javascript Session Timeout with warning

查看:165
本文介绍了带有警告的PHP / Javascript会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我可以在哪里阅读教程,或者知道如何创建一个内置警告的基于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:


  • 用户活动重置计时器

  • 与数据库交互(最后一次见到等)

  • 如果不活动,它会在用户退出之前注销用户(通过重定向到logout.php
    页面)

  • ,它会显示一条弹出消息,询问
    想继续

  • 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

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

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

推荐答案

我不知道你的网站是如何完成的,但是如果做得对,你应该有一个登录会话和某种后端控制系统,否则任何行动如果之前的操作是在X分钟/小时前完成的,并自动使用户过期。如果你想实现一些客户端代码,你应该有一个javascript定时器,当过期时间即将完成时提醒用户,你也可以在达到过期时间后将用户重定向到主页或登录页面。这样所有安全功能都在后端,javascript只能用作显示行为的显示度量。

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.

更新:

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"
}

每个有此代码的页面都会在10分钟后询问是否用户想要注销。这意味着您的会话本身不会过期,您必须将控件留给用户

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

这篇关于带有警告的PHP / Javascript会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆