500 Error with password_verify()
本问题已经有最佳答案,请猛点这里访问。
出于某些我自己不知道的原因,当我尝试用这个登录脚本加载一个页面时,我收到一个500错误。我知道这与if语句有关,但我不确定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php //Start the Session session_start(); require('connect.php'); if (isset($_POST) & !empty($_POST)){ $username = $_POST['username']; $password = $_POST['password']; $sql = $connection->prepare("SELECT * FROM login WHERE username=username"); $sql->bindParam('username', $username); $sql->execute(); if(($row = $sql->fetch()) && (password_verify($$password,$row['password']))){ echo"hurray, you authenticated.<br/>"; } else { //header("Location:../../login/login.p echo"invalid login<br/>"; } ?> |
这是供参考的注册脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php require_once('connect.php'); if(isset($_POST) && !empty($_POST)){ $username = mysqli_real_escape_string($connection, $_POST['username']); $email = mysqli_real_escape_string($connection, $_POST['email']); $password =$_POST['password']; $password = password_hash($password,PASSWORD_BCRYPT); $sql = $connection->prepare("INSERT INTO `login` (username, email, password) VALUES (?, ?, ?)"); $sql->bind_param("sss", $username, $email, $password); $sql->execute(); if($sql){ echo"User Rego Secussefull"; }else{ echo"User rego failed"; } } ?> |
如果
您可以更改为简化您的第一个if,以:
或
1 |