[英]How do I make my site automatically sign out a user when they close their browser?
Let's suppose I have a sign-in form. 假设我有一个登录表单。 When I sign in successfully I am redirected to the logged in home page. 成功登录后,我将被重定向到登录的主页。 Currently, when I close this page without signing out, and re-open Firefox, this logged in home page is started again. 当前,当我不退出而关闭此页面并重新打开Firefox时,此登录的主页将再次启动。
I want it so that when the user closes their browser the session is the session is expired and when they next open Firefox the logged-in home page isn't displayed. 我想要这样,以便当用户关闭其浏览器时,会话即会话已过期,而当他们下次打开Firefox时,不会显示登录的主页。
I think session will be used for this, but I don't know how I can set a time or even make it so that when Firefox closes the closes session get destroyed. 我认为会话将用于此目的,但是我不知道如何设置时间,甚至无法设置时间,以便在Firefox关闭时关闭会话。
You want the session cookie to have an expire time of 0 - see: 您希望会话cookie的到期时间为0-请参阅:
http://php.net/manual/en/function.setcookie.php http://php.net/manual/en/function.setcookie.php
http://docs.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime http://docs.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime
Set your session timeout to 15 minutes, this should do the job. 将您的会话超时设置为15分钟,这应该可以完成。 You cannot catch the "close browser" or "close tab" event for sure (no javascript enabled, browser just crashes, etc), so you shouldn't go for that. 您不能确定捕获“关闭浏览器”或“关闭选项卡”事件(未启用JavaScript,浏览器崩溃等),因此您不应该这样做。
Check Felix' post for additional information where to set the session timeout exactly. 查看Felix的文章,以获取其他信息,以了解确切设置会话超时的位置。
Pardon me if I am stepping on toes as non-server HTML programmer, but could you check to see if the browser already has a cookie from a previous session? 如果我以非服务器HTML程序员的身份踏上脚步,请原谅我,但是您能检查一下浏览器是否已有上一个会话的cookie吗? Even if the answer is yes, if it is a new session, force an authentication? 即使答案是肯定的,即使是新会话,也要强制进行身份验证?
Just a thought. 只是一个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.