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 ?

3
  • what version of PHP do you have? if you take a look at the documentation jp.php.net/manual/zh/function.hash.php, you would notice that you need a PHP 5 >= 5.1.2 or the pecl module ..... Commented Apr 8, 2011 at 7:42
  • Do you have hash enabled in your phpinfo(); Commented Apr 8, 2011 at 7:43
  • Hi there. Which Php version are you using? Be sure hash is defined in that version... Commented Apr 8, 2011 at 7:43

5 Answers 5

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

2

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

Comments

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

Comments

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.