PHPで作成した現在のログインスクリプトは機能していますが、ログインして[Remember me]のチェックを外そうとするとログインしますが、必要なCookieが設定されません。ただし、[Remember]ボックスをオンにすると、ログインして設定されます。クッキー。だから問題は、それが起こった原因は何ですか?私のPHPコード:
<?php
/* Mysql data */
$MysqlUsername = "root";
$MysqlPassword = "";
$MysqlHostname = "localhost";
$MysqlDatabase = "teamgamersnet";
$Salt = "TGN2012";
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Remember = $_POST['Remember'];
$Cookie = "TGN";
$IP = $_SERVER['REMOTE_ADDR'];
if (empty($Username) || empty($Password)) { die("Please fill in all the fields"); }
$hash = hash('sha256',strtolower($Username).$Password.$Salt);
$Sql = new mysqli($MysqlHostname, $MysqlUsername, $MysqlPassword, $MysqlDatabase);
if ($Sql->connect_error){ echo $Sql->connect_error; }
$sUser = $Sql->real_escape_string($Username);
$sPass = $Sql->real_escape_string($Password);
$xPass = $Sql->real_escape_string($hash);
$CheckUser = $Sql->query("SELECT * FROM `users` WHERE `Username` = '".$sUser."'");;
if ($CheckUser->num_rows == 0) { header("Location: /?p=Login&wrongusr=true"); die(); }
$xCheckUser = $CheckUser->fetch_array(MYSQLI_ASSOC);
if ($xCheckUser['Activated'] == "false") { header("Location: /?p=Login&activate=true"); die(); }
if(strtolower($Username) == strtolower($xCheckUser['Username'])) {
if($hash == $xCheckUser['Password']) { // Check if password is correct
if(isset($Remember)){ // Set a looong cooke to remember
setcookie ($Cookie."User", htmlspecialchars($Username), time() + 99999999);
setcookie ($Cookie."Pass", $hash, time() + 99999999);
header("Location: /?login=true");
}
else
{ // Set a standard cookie
setcookie ($Cookie."User", htmlspecialchars($Username), time() + 3600);
setcookie ($Cookie."Pass", $hash, time() + 3600);
header("Location: /?login=true");
}
}
else
{
header("Location: /?p=Login&wrongpwd=true"); // Send them to home page
}
}
?>