简体   繁体   English

处理用户登录令牌

[英]Handling user login tokens

So I want users to be able to login from different computers simultaneously. 因此,我希望用户能够同时从其他计算机登录。 So that means I should allow the user to have multiple tokens. 因此,这意味着我应该允许用户拥有多个令牌。 And then I also want the user to be able to login from different browsers on the same computer. 然后,我还希望用户能够从同一台计算机上的不同浏览器登录。 So that means I should allow the user to have multiple tokens for same IP. 因此,这意味着我应该允许用户为同一IP使用多个令牌。 However, it's gonna get messy because eventually I'm going to have alot of tokens for one user! 但是,它会变得混乱,因为最终我将为一个用户准备很多令牌!

Any suggestions on strategy of controlling this or am SOL that I would need to do a token clean up for tokens that are not used for say 15 days or so? 关于控制此策略或SOL的策略方面的任何建议,我需要对未使用15天左右的令牌进行令牌清除? Sorry, I just want to get it right :) 抱歉,我只是想找对它:)

PS I'm doing this with PHP PS我正在用PHP做到这一点

Not sure what kind of answer you are waiting for, but you might want to use the Session Handling mecanism that comes with PHP, to store the data of your users' sessions. 不确定您正在等待哪种答案,但是您可能想使用PHP附带的会话处理机制来存储用户会话的数据。

It's based on a cookie that's used to store the "token" that points to the session -- which means each user can have a distinct session on each one of bots his browsers and computers ; 它基于一个cookie,该cookie用于存储指向会话的“令牌”,这意味着每个用户在其浏览器和计算机上的每个机器人上都可以有一个不同的会话; and works pretty fine. 并且工作得很好。

With that, you just have to call session_start() at the beginning of your script, and use $_SESSION in it -- and that's pretty much everything you have to care about : PHP will deal with sessions' expiration itself. 这样,您只需要在脚本的开头调用session_start() ,并在其中使用$_SESSION ,这几乎就是您要关心的一切:PHP会自行处理会话的到期时间。

Just use PHP's built-in session controls . 只需使用PHP的内置会话控件 It will automatically generate a token for each session, which is saved in a cookie. 它将为每个会话自动生成一个令牌,并保存在cookie中。 You can then have a login flag (for example $_SESSION['login'] ) that you set to true once the use have logged in, and a username or userid variable ( $_SESSION['user'] ) where you can save which user that browser is authenticated as. 然后,您可以拥有一个登录标记(例如$_SESSION['login'] ),一旦使用已登录,就可以将其设置为true;还有一个用户名或用户ID变量( $_SESSION['user'] ),您可以在其中保存哪个浏览器被认证为的用户。

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

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