23

I am running php version 5.4.16 on localhost right now, while I am developing my site. I want to use password_hash(), but I keep getting this error:

Fatal error: Call to undefined function password_hash() in /dir/to/file.php on line 123

Why is this happening?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user3162085
  • 241
  • 1
  • 2
  • 3

1 Answers1

31

The new password_* methods are only available as of PHP 5.5:

http://www.php.net/manual/en/function.password-hash.php

Take a look at this library that provides forward compatibility:

https://github.com/ircmaxell/password_compat

You can use that to get access to the new password_* methods until you are able to run PHP 5.5.

jszobody
  • 28,495
  • 6
  • 61
  • 72
  • 1
    What are the alternatives in older versions of PHP? – Doug Mar 12 '15 at 14:08
  • 1
    for older versions use crypt() http://php.net/manual/en/function.crypt.php You can use hashes made with password_hash together with crypt – astroanu Dec 22 '15 at 04:50