PHP 登录不起作用

标签 php mysql authentication

我有一个简单的登录系统,但无法正常工作,我也不知道为什么。一旦我按下登录按钮,没有任何反应,网站只是重新加载,而不是重定向我或给我任何错误消息。

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/

相关文章:

php - 如何处理大表上的左连接?有意想不到的行为

java - 如何在有限时间后使购物车过期

php - is_uploaded_file() 的目的是什么?

java - JPA 中的参数化查询出现 "org.hibernate.QueryException: Unable to resolve path..."错误

mysql - SQL根据订单数统计人数

php - 最安全的 PHP 'access denied' 方法

azure - ADAL 身份验证 token 与 Postman token Oauth2 不同

php - 无法将输入的 $username 插入表中

java - 使用 javascript 和 PHP 开发原生 android 应用程序

python - 使用 python-mysql、tornado 框架检索列值