我有一个简单的登录系统,但无法正常工作,我也不知道为什么。一旦我按下登录按钮,没有任何反应,网站只是重新加载,而不是重定向我或给我任何错误消息。
if(!empty($_POST['email']) && !empty($_POST['password'])){
$records = $conn->prepare('SELECT email, password FROM Profiles WHERE email = :email');
$records ->bindParam(':email', $_POST['email']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if(count($results) > 0 && password_verify($_POST['password'], $results['password'])){
$_SESSION['user_email'] = $results['email'];
header("Location: main.php");
}else{
$message = 'Sorry, those credentials do not match';
}
}
这是 HTML 表单。
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<input type="text" placeholder="Email" name="email"> <br/> <br/>
<input type="password" placeholder="Password" name="password"> <br/> <br/>
<input type="submit" value="Login">
</form>
最佳答案
来自(我的)评论:
"my guess is and this has happened often before, is that the password column's length isn't long enough. If that is the case, then that failed silently, which is what I said earlier and was in regards to that. If the column is anything less than 60, then you will need to start over, delete the old hashes, ALTER the column to be 60+ (255 is better) and create a new set of hashes. I've answered quite a few questions like this and because of that. . – Fred -ii- "
和OP:
@Fred-ii- You were right and it's working now! Thank you so much! No wonder this has been bugging me for hours. – Krillex"
关于PHP 登录不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42753661/