简体   繁体   English

当用户在网页上时,定期询问用户是否希望保持登录状态的最佳方式是什么?

[英]What is the best way to periodically ask a user if they wish to remain logged-in when the user is on a web-page?

In order to protect member users' information that is maintained by my web-site and, in general, proprietary information on my web-site, my web-site requires that users create accounts and then log into their accounts before they can navigate away from my web-site's home page to other web-pages in my web-site.为了保护由我的网站维护的会员用户信息以及我网站上的一般专有信息,我的网站要求用户创建帐户,然后登录他们的帐户,然后才能离开我网站的主页到我网站中的其他网页。 However, it isn't enough that the users simply login to their accounts, they also need to use the system by navigating through the web-pages in my web-site or, on some pages, operate the controls in the web-page or type-in data into the form field controls.然而,用户仅仅登录他们的账户是不够的,他们还需要通过浏览我网站中的网页来使用系统,或者在某些页面上,操作网页中的控件或在表单域控件中输入数据。 Thus proving that they are still using the site and not just left one of my web-sites web-page unattended and open to someone else.从而证明他们仍在使用该网站,而不仅仅是让我的网站之一无人看管并向其他人开放。 Additionally, I'd like to prevent someone who finds one of my web-page in the browser's history and then try jumping to that web-page to hijack a user's account.此外,我想阻止有人在浏览器的历史记录中找到我的网页之一,然后尝试跳转到该网页以劫持用户的帐户。

Other than the home web-page in my web-site, when one of my web-pages is requested, my web-site's server-side php code calculates an expiration datetime, which then checked against the system's datetime to see if the user is still logged-in.除了我网站中的主页之外,当我的一个网页被请求时,我网站的服务器端 php 代码会计算到期日期时间,然后对照系统的日期时间检查用户是否仍然登录。 This check is performed when a requested web-page first loads into the user's browser with JavaScript code.当请求的网页首次使用 JavaScript 代码加载到用户的浏览器时,会执行此检查。 This check is also performed when a web-page in my web-site is requested with the web-site's server-side php code.当使用网站的服务器端 php 代码请求我的网站中的网页时,也会执行此检查。 In either of these checks, if the expiration datetime is earlier than the system's current datetime, then the user is automatically logged-out and returned to my web-site's home web-page.在这些检查中的任何一个中,如果到期日期时间早于系统的当前日期时间,则用户将自动注销并返回到我网站的主页。

However, there are some pages in my web-site where the logged-in member user has to enter large amounts of information into the web-page and then post that data to the server, but if they take too long to do this then they will loose that information when they are automatically logged-out.但是,在我的网站中有一些页面,登录的会员用户必须在网页中输入大量信息,然后将这些数据发布到服务器,但如果他们这样做的时间太长,那么他们当他们自动注销时将丢失该信息。 Instead, before the expiration datetime expires, I want to ask the user if they wish to remain logged-in, similar to what banks do when in their online banking system.相反,在到期日期时间到期之前,我想询问用户是否希望保持登录状态,类似于银行在其网上银行系统中所做的事情。

What is the best way to do this?做这个的最好方式是什么?

Two ways come to mind that both display a message to the user, asking if the user wants to extend their logged-in session.我想到了两种方式,它们都向用户显示一条消息,询问用户是否要扩展他们登录的 session。 If the user answers yes, then the expiration datetime is extended by another 20 minutes.如果用户回答是,则到期日期时间再延长 20 分钟。 If the user answers no or the question goes unanswered, then the user is automatically logged-out and then redirected to my web-site's home web-page:如果用户回答“否”或问题没有得到回答,则用户会自动注销,然后重定向到我网站的主页:

  1. Let the server periodically send a message (polling) to each user's browser to cause the user to be prompted about remaining logged-in.让服务器定期向每个用户的浏览器发送消息(轮询),以提示用户保持登录状态。

  2. When each web-page loads, it starts a timer that when it times-out then prompts the user about remaining logged-in.当每个网页加载时,它会启动一个计时器,当它超时时会提示用户保持登录状态。

The first method seems to be much more difficult and I don't know how to do this.第一种方法似乎要困难得多,我不知道该怎么做。

The second method, while much easier, seems like it would be possible for a malicious user to defeat.第二种方法虽然容易得多,但恶意用户似乎有可能击败。

This all heavily relies on all web-page requests to be blocked by my web-server's php code, or in the case of one of my web-pages being reloaded from the browser's history, the JavaScript code in the web-page detect this, logout the user and redirect to my web-site's home web-page.这一切都严重依赖于被我的网络服务器的 php 代码阻止的所有网页请求,或者在我的网页之一从浏览器的历史记录中重新加载的情况下,网页中的 JavaScript 代码检测到这一点,注销用户并重定向到我网站的主页。

Is there a way to compile the browser-side JavaScript or some other code that handles the expired login-session check so that a malicious user's can't defeat it using the browser's code inspector?有没有办法编译浏览器端 JavaScript 或其他处理过期登录会话检查的代码,以便恶意用户无法使用浏览器的代码检查器击败它? Would this be possible in a web-api?这在 web-api 中可行吗?

Any ideas?有任何想法吗?

Thanks.谢谢。

You could do the following..您可以执行以下操作..

1.After successfully logged in, Store user logged in time in browser storage such as LocalStorage, Indexed DB or Cookie Storage, 1.登录成功后,将用户登录时间存储在LocalStorage、Indexed DB或Cookie Storage等浏览器存储中,

2.Using javascript u can compare Current time and user logged in time. 2.使用 javascript 可以比较当前时间和用户登录时间。

3.After certain interval may be 30min/1hour you can prompt the user about if he wants to remain logged-in. 3.在一定的间隔可能是30分钟/1小时后,您可以提示用户是否要保持登录状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM