Home > Backend Development > PHP Tutorial > PHP实现一个账号只能一个用户登录

PHP实现一个账号只能一个用户登录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:28:14
Original
1830 people have browsed it

思路:


用户登录时,将函数session_id()的值写入到数据库中,这样就能始终保证数据库中的session_id的值是最新的登录的用户对应的session

_id。


在页面验证用户时,需要验证用户当前的session_id和数据库中session的值是否一致。


举例:


已知有一个账号U,两个用户A和B。


首先A登录账号U,于是用户A登录时,对应的session_id写入到账号U对应的session_id中,此时用户A保持登录状态。


然后B也登录账号U,用户B登录时,对应的session_id更新了账号U对应的session_id的值。


此时,对A用户进行验证时就会发现,A对应的session_id的值与数据库中的不一致,系统提示A用户,有其他用户登录账号U。


参考文章:

http://www.zhihu.com/question/19976722

版权声明:本文为博主原创文章,未经博主允许不得转载。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template