我有一個註冊/登錄系統的PHP網站。出於安全原因,我希望用戶一次只能從一臺PC登錄。如果在用戶使用該ID /密碼登錄時相同的ID /密碼嘗試從另一臺PC登錄,則應該生成錯誤消息。如何一次只能從一臺計算機登錄一個身份證/通行證
請告訴我它是如何可能的,什麼是做到這一點的最好方法是什麼?
我只用餅乾...
<?php function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = false; // Set to true if using https.
$httponly = true; // This stops javascript being able to access the session id.
ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies.
$cookieParams = session_get_cookie_params(); // Gets current cookies params.
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
session_name($session_name); // Sets the session name to the one set above.
session_start(); // Start the php session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
下面是代碼:
if(login($name, $password, $mysqli) == true) {
// Login success
if($name == 'admin'){
if($signin == 'zero'){
$stmt = $mysqli->prepare("UPDATE users SET signin = 'one' WHERE name = 'admin'");
$stmt->execute();
?>
<span class="TextFont"><br /><br />Welcome Admin! <a href="admin.php">Click here to access your Admin Panel</a>! <br /><br /> <a href="logout.php">Logout</a></span>
<?php }
else{
echo"You are already logged in from some other system! $signin";
}}
else{
// some PHP code
}
else{
// some PHP code
}
添加一個額外的行表,它是用戶登錄0或每次1個校驗值,如果是1返回false,否則可以登錄 – jycr753
如果你共享一個db結構的樣本,並且你如何登錄將會很容易幫助 – jycr753
@ jycr753!我在登錄時啓動安全會話並在PHP的每個頁面上使用它。請看看我剛剛添加的代碼,並讓我知道這些漏洞。並感謝您的解決方案,我可能會實施它。 – user2548130