20

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.

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206
H Bellamy
  • 22,405
  • 23
  • 76
  • 114

4 Answers4

41

You can use

hash( 'sha256', $string );

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

DarkDevine
  • 1,047
  • 1
  • 9
  • 12
5

The Suhosin extension adds the function sha256(), and even sha256_file(), to the PHP Core.

With the extension installed:

<?php
var_dump(function_exists('sha256'));
?>

bool(true)
newfurniturey
  • 37,556
  • 9
  • 94
  • 102
3

There is no such function in php standard library. Use hash function instead. http://php.net/manual/en/function.hash.php like :

$pass = hash('sha256', $_POST['password']);
Yuck
  • 49,664
  • 13
  • 105
  • 135
Wieszos
  • 31
  • 2
0

ehrm. That function doesn't exist. If you want to use the SHA256 algorithm, use hash instead.

Berry Langerak
  • 18,561
  • 4
  • 45
  • 58