This article mainly introduces how php effectively prevents multiple logins of the same account at the same time. if you are interested, refer
[Problem description ]:It is dangerous for a single user to log on multiple times at the same time. Because, you cannot know if other users are logging on to your account. How Can I disable multiple logins from the same user?
[Solution]
(1) A new session_id is generated after the identity authentication is successful upon each login.
session_regenerate_id(); session_register ("username") ;
(2) open a sessionid field in the user database. after the session_id is re-generated, the field is updated.
$sessionid = session_id(); $db = new PDO('sqlite:softToken.db'); $sql = "update userinfo set sessionid ='$sessionid' where username='$username' and passwd='$passwd';"; $query = $db->prepare($sql); $query->execute();
(3) Create a session to save the user name
$_SESSION["username"] = $username;
(4) use url rewriting to pass session_id
$ Url = "main. php? Sid = ". session_id (); unset ($ db); echo" login successful, jump! "; Header (" Location: $ url ");
(5) add
Main. php
<? Php header ('content-type: text/html; charset = utf-8 '); $ sessionid = $ _ GET ['Sid']; session_id ($ sessionid); session_start (); $ username = $ _ SESSION ["username"]; $ db = new PDO ('sqlite: softToken. db'); $ SQL = "select * from userinfo where username = '$ username' and sessionid =' $ sessionid ';"; $ query = $ db-> prepare ($ SQL); $ query-> execute (); $ user = $ query-> fetch (PDO: FETCH_OBJ ); if ($ user-> username = "") {session_destroy (); echo"