Undefined function sha256()

H Bellamy picture H Bellamy · Dec 16, 2011 · Viewed 22.8k times · Source

I have this php code:

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

but when I run this code it says:

Fatal error: Call to undefined function sha256() in .... on line ...ix it as 

What is wrong with this code and what must I do to fix this as I know that sha256 exists.

I have also tried:

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

But that doesn't work either.

Answer

DarkDevine picture DarkDevine · Dec 16, 2011

You can use

hash( 'sha256', $string );

See http://de.php.net/manual/de/function.hash.php