0

PHP password_hash() and password_verify() functions work on localhost, but not on my server.

Hi everyone, this might be a problem specific to me,but I can't for the life of me figure out why it's happening. I tried running this simple php script:

<?php
echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT);
?>

On my localhost, this code works perfectly fine and displays something like this:

$2y$10$BMuRYvrhQbPduARvea7aLe4kwzrahfkvscEmzxvVdF8Y80f5ZxX5C

However, when trying to run the same exact script on a server, this function doesn't work. Nothing is displayed and when I try writing other code after this function, like:

echo"hi";

this doesn't display either. This means that some kind of error is occurring with the password_hash() function. I'm having the same problems with password_verify().

I checked the php versions of my server and localhost.

localhost: php version: 5.6.31 server: php version 5.4.16

Is there a problem with the server's php version or is it a problem that's most likely specific to my server only?

Josh Smith
  • 19
  • 3
  • real simple, it's your php version and you should be getting an error about it being undefined, but your system isn't setup to catch and display errors; error reporting would have helped. – Funk Forty Niner Jul 24 '17 at 22:19
  • Note that `password_hash` is PHP 5.5+ but you can install [this library](https://github.com/ircmaxell/password_compat) to get it on your live server since it is running 5.4 – Machavity Jul 24 '17 at 22:33
  • Thank you so much! These comments were super helpful! I installed the library like Machavity said and it worked like a charm! – Josh Smith Jul 24 '17 at 23:14

0 Answers0