dprfe04886
2014-04-15 01:19
浏览 120
已采纳

为什么PHP的“password_hash”不返回字符串?

<?php
    $connection=new PDO("mysql:host=localhost;dbname=userdata", "secure_credentials", "battery_staple");
    $user=$_POST['username1'];
    $pass=$_POST['password1'];
    $snip=mb_substr($user, 0, 3);
    $pass=password_hash($pass, PASSWORD_BCRYPT);
    $user_query=$connection->prepare("INSERT INTO login (email, password, semod, snippet) VALUES (:email, :password, :semod, :snippet)");
    $user_query->bindParam(':email', $user);
    $user_query->bindParam(':password', $pass);
    $user_query->bindParam(':semod', "false");
    $user_query->bindParam(':snippet', $snip);
    $user_query->execute;

(Password changed)

I'm facing a small problem with the above PHP code, whenever it's executed I get this error:

Fatal error: Cannot pass parameter 2 by reference in [location] on line [##: I shortened the above code... it's the password field with issues]

Looking around, this seems to be an issue when passing an string/integer directly, without using a variable. However, password_hash() returns a string, so I am led to believe that it's not returning a string. What could be the problem of this issue?

图片转代码服务由CSDN问答提供 功能建议

 &lt;?php 
 $ connection = new PDO(“mysql:host = localhost; dbname =  userdata“,”secure_credentials“,”battery_staple“); 
 $ user = $ _ POST ['username1']; 
 $ pass = $ _ POST ['password1']; 
 $ snip = mb_substr($ user,0,  3); 
 $ pass = password_hash($ pass,PASSWORD_BCRYPT); 
 $ user_query = $ connection-&gt; prepare(“INSERT INTO登录(电子邮件,密码,semod,代码段)VALUES(:email,:password,:  semod,:snippet)“); 
 $ user_query-&gt; bindParam(':email',$ user); 
 $ user_query-&gt; bindParam(':password',$ pass); 
 $ user_query-&gt  ; bindParam(':semod',“false”); 
 $ user_query-&gt; bindParam(':snippet',$ snip); 
 $ user_query-&gt; execute; 
    
 
 

(密码已更改)

我遇到上述PHP代码的小问题,无论何时执行我都会收到此错误: \ n

致命错误:无法通过引用传递参数2 [位置] 在线 [##:我缩短了上述c ode ...这是带有问题的密码字段]

环顾四周,这似乎是直接传递字符串/整数的问题,不使用变量。 但是, password_hash()返回一个字符串,因此我认为它没有返回字符串。 这个问题可能是什么问题?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题