我正在学习一个创建注册和登录系统的教程。我正在做同样的事情,但当我在表格上按提交时,我仍然会收到一个奇怪的严格标准错误。
<?php
require 'pdoconnect.php';
$message = '';
if(!empty($_POST['email']) && !empty($_POST['password'])):
// Enter the new user in the database
$sql = "INSERT INTO users (email, password) VALUES (:email, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = 'Successfully created new user';
else:
$message = 'Sorry there must have been an issue creating your account';
endif;
endif;
?>
它说
严格的标准:只有变量应该通过第14行的引用传递(带有密码哈希的行)。
我到处寻找解决方案,但我找不到任何解决方案。
答案 0 :(得分:1)
在绑定密码之前隐藏密码:
// Enter the new user in the database
$sql = "INSERT INTO users (email, password) VALUES (:email, :password)";
$stmt = $conn->prepare($sql);
$hashedPass = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', $hashedPass );
您无法将函数传递给绑定参数,只能传递变量。