2017-02-18 8 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に記載されているように、関数の2番目のパラメータは変数参照であり、代わりに関数の結果を渡そうとします。したがって、関数の結果を変数に格納し、それを関数に渡すことができます。

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

注:ハッシュ処理は暗号化ではありません – RiggsFolly

+0

あなたは間違いありません。変数名。 – knetsi

関連する問題