douxu3732 2013-05-29 14:40
浏览 20
已采纳

一小时后可靠的自动注销

I have some javascript that is supposed to log you out after an hour but it has some problems, first of all, it doesn't logout you out after an hour, its normally about 20 minutes, and secondly it doesn't always work 100% of the time, say I leave my PC on overnight sometimes I am still logged in (maybe not in the PHP session) and on the same page.

I have a feeling if the screen turns off it pauses the javascript counter.

The code is:

var delay = 3600000;
setTimeout(function(){ window.location =  base_url + 'user/logout' }, delay);

Is there a better more reliable way of doing this? How is it done on banking sites?

EDIT: I don't mean this will actually log out the user, of course that is done server side, I just want the page to automatically redirect to the login page after an hour, just like the banks say "You have been logged out due to inactivity".

This is because there will be sensitive data that I don't want being left on someone's screen overnight

  • 写回答

1条回答 默认 最新

  • dongpu9852 2013-05-29 15:08
    关注

    You can attach focus and blur event handlers on the window object to track if the window gets or loses focus.

    Also, it's bad idea to logout user after timeout (there can be user activity, ajax requests). Better to check that session is alive at server-side by ajax request and only when it's expired, delete document content and show popup with message about session expiration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?