2017-02-18 229 views
-1

我正在练习编码,并正在使用我从YouTube上观看的视频制作登录系统。当我尝试注册一个帐户时,一切正常,但唯一的问题是它给了我一个小错误,说明这一点:严格标准:只有变量应该通过/home/login-name/public_html/login/register.php中的引用传递线9错误:严格标准:只有变量应该通过引用传递?

Register.php

<?php 
require 'database.php'; 

if(!empty($_POST['username']) && !empty($_POST['password'])): 
    $sql = "INSERT INTO users (username, password) VALUES (:username, :password)"; 
    $stmt = $conn->prepare($sql); 

    $stmt->bindParam(':username', $_POST['username']); 
    $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT)); 

    if($stmt->execute()): 
     die('Success'); 
    else: 
     die('Fail'); 
    endif; 
endif; 
?> 

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <title>Register</title> 
     <meta charset=utf-8> 
     <link href="../css/register.css" rel="stylesheet"> 
     <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> 
    </head> 
    <body> 
     <div class="header"> 
      <span class="header-logo"><a href="home">Abyssal Test</a></span> 
     </div> 
     <form action="register" method="POST"> 
      <input type="text" placeholder="Username" name="username"> 
      <input type="password" placeholder="Password" name="password"> 
      <input type="password" placeholder="Confirm Password" name="confirm_password"> 
      <input type="submit" name="register" value="Register"> 
      <span class="register-text">Already have an account? <a href="login">Login Here</a></span> 
     </form> 
    </body> 
</html> 
+0

就像错误状态一样。你需要重写'$ stmt-> bindParam(':password',password_hash($ _ POST ['password'],PASSWORD_BCRYPT));' –

回答

2

改变这一行

$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT)); 

$hash = password_hash($_POST['password'], PASSWORD_BCRYPT); 
$stmt->bindParam(':password', $hash); 
1

因为它在函数“bindParam”的documentation中声明了函数的第二个参数是一个变量引用,所以您尝试传递函数结果。因此,您可以将函数的结果存储在变量中,然后将其传递给函数

$passwordHash=password_hash($_POST['password'], PASSWORD_BCRYPT); 
$stmt->bindParam(':username', $_POST['username']); 
$stmt->bindParam(':password', $passwordHash); 
+0

注意:HASHING不是ENCRYPTION – RiggsFolly

+0

你是对的,我的错误发生了变化变量名称。 – knetsi

相关问题