"Problem description": the same user logged on multiple times at the same time if it is not detected, it is dangerous. Because, you can't know if any other users are logged in to your account. How do I prevent the same user from logging on multiple times?
"Solution"
(1) Each login, the success of identity authentication, the session_id of a new generation.
SESSION_REGENERATE_ID ();
Session_register ("username");
(2) A SessionID field is opened in the user database, and the field is updated after the session_id is generated.
$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) Establish a session to save the user name
$_session["username"] = $username;
(4) Use URL rewrite, pass session_id
$url = "main.php?sid=". session_id ();
Unset ($db);
echo "<font color=blue> login success, is jumping!</font>";
Header ("Location: $url");
(5) in the need to jump to the page, at the beginning of the join
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 "<script language= ' javascript ' type= ' text/javascript ' >";
echo "window.location.href = ' index.html ';";
echo "</script>";
Exit ();
>
The above is a valid PHP to prevent the same account number of times the same time to log on the solution, I hope to solve the same account at the same time multiple login problems help.