登录,注销和持续时间在PHP和MySQL? [英] Login, logout and duration time in php and mysql?

查看:95
本文介绍了登录,注销和持续时间在PHP和MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将登录,注销和持续时间存储在数据库中.

I would like to store the login, logout and duration time in database.

  • 登录时间是在对用户进行身份验证(成功登录)后创建的
  • 注销时间是在用户单击注销按钮时创建的
  • 持续时间为注销-登录时间. (注销减去登录名)

但是问题是,如果用户没有单击注销按钮,该怎么办.情况如下:

But the problem is, what if the user didnt click the logout button. Here are the situations:

  • 互联网丢失
  • 关闭浏览器/选项卡. (我需要使用javascript,但是我donnu怎么做,有什么主意吗?)

我忘了添加一些问题,该程序是完整的Flash程序,没有导航到其他页面.只有一页

I forgot to add something to the question, the program is a full flash program, there is no navigation to other page. Only 1 page

推荐答案

如果用户只是关闭浏览器或从互联网上消失,则不能依赖于用户注销事件.

You can't rely on receiving an event for the user logging out, if they simply close their browser, or disappear from the internet.

在这种情况下,您将必须有某种会话超时,并在您的应用意识到他们的会话太旧时记录注销信息.

In this case you'll have to have a session timeout of some kind, and record the logout when your app realises their session is too old.

如果这是真正的要求,那么我想说您需要一个"cron"作业来监视会话超时.会话超时后(如果已登录),它将为该用户记录一个注销"事件.

If this is a real requirement, then I'd say you need a "cron" job monitoring the sessions for timeout. When a session has timed out, if the were logged on, it then records a "logout" event for that user.

请注意,您不能使用(例如)ASPNET的Session_End事件,因为也不会可靠地调用该事件(例如,如果服务器进程重新启动).

Note that you can't use (for example) ASPNET's Session_End event, because that won't be reliably called either (for example if the server process restarts).

另一种选择是添加下次用户登录时的注销时间-登录时,您检查旧会话并假定自上次命中页面以来未关闭的会话持续了固定的时间.

Another option is to add the logout time next time that user logs on - when they log on, you check for old sessions and assume that any which weren't closed lasted for a fixed amount of time since the last page hit.

那真的是你所能做的.

这篇关于登录,注销和持续时间在PHP和MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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