0
下面的代碼不起作用:PHP登錄使用password_hash
登錄頁面:
if (isset($_POST['login'])) {
$name = $mysqli->real_escape_string($_POST['name']);
$pass = $_POST['pass'];
$query = "SELECT * FROM users WHERE name='{$name}'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if(password_verify($pass, $row['pass'])){
$_SESSION['logged'] = true;
$_SESSION['name'] = $row['name'];
$_SESSION['pass'] = $row['pass'];
//header('Location: index.php');
echo "Workded";
} else {
echo "Crypt Not Matching";
}
}
}
}
代碼用於插入到數據庫:
if (empty($e1)) {
$password = password_hash($pass, PASSWORD_BCRYPT);
if ($mysqli->query("INSERT into users (name, pass, email, gamertag, psnid, youtube, fbauth) VALUES ('$username', '$password', '$email', '$xbox', '$psn', '$youtube', '$fbid')")) {
session_start();
$_SESSION['logged'] = true;
$_SESSION['name'] = $username;
$_SESSION['pass'] = $password;
header('Location: index.php');
}
}
任何人都可以指出我什麼做錯了?
有什麼不好?你遇到了什麼錯誤?你會得到什麼?你期望得到什麼? – Tivie 2013-05-09 00:30:32
沒有錯誤,只是想驗證登錄。而將登錄密碼與存儲在數據庫中的登錄密碼相匹配以初始化會話並登錄用戶。 – 2013-05-09 00:31:35