0

I have called hash function in my code like (php version 5.2.14 )

$username =hash("sha256",trim($_POST['username']));
$password =hash("sha256",trim($_POST['password']));

but I got error like Call to undefined function hash() in /var/www/site/ What to do ?

Damir
  • 54,277
  • 94
  • 246
  • 365
  • what version of PHP do you have? if you take a look at the documentation http://jp.php.net/manual/zh/function.hash.php, you would notice that you need a PHP 5 >= 5.1.2 or the pecl module ..... – RageZ Apr 08 '11 at 07:42
  • Do you have hash enabled in your phpinfo(); – S L Apr 08 '11 at 07:43
  • Hi there. Which Php version are you using? Be sure hash is defined in that version... – Nobita Apr 08 '11 at 07:43

5 Answers5

4

It means it cannot find the function hash(). Checking the manual I see this:

(PHP 5 >= 5.1.2, PECL hash >= 1.1)

What php version do you run? Try:

<? phpinfo() ?>

To check. If it is lower then 5.1.2 you do not have the hash() function available

Nanne
  • 64,065
  • 16
  • 119
  • 163
2

'hash()' was introduced in PHP 5.1.2, so it's possible you have an older version.

ctford
  • 7,189
  • 4
  • 34
  • 51
2

Check your PHP version because the hash function is only available for version PHP 5 >= 5.1.2 with PECL hash >= 1.1

Osh Mansor
  • 1,232
  • 2
  • 20
  • 42
1

If your version of PHP > 5.1.2, then enable the hash extension by uncommenting its line in the php.ini config file in use and restarting the web server

kakoma
  • 1,179
  • 13
  • 17
0

If you do have an older version, you can still revert to the sha1 or sha256 functions as follows:

$username = sha1(trim($_POST['username']));
$password = sha1(trim($_POST['password']));

OR

$username = sha256(trim($_POST['username']));
$password = sha256(trim($_POST['password']));

HOWEVER there is a good argument about both here: SHA1 vs md5 vs SHA256: which to use for a PHP login?

Community
  • 1
  • 1
SimonDowdles
  • 2,026
  • 4
  • 24
  • 36