php 未定义的函数 sha256()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8533530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:55:42  来源:igfitidea点击:

Undefined function sha256()

phpcryptographyundefinedtrimsha256

提问by H Bellamy

I have this php code:

我有这个 php 代码:

$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 sha256exists.

这段代码有什么问题,我必须做些什么来解决这个问题,因为我知道它sha256存在。

I have also tried:

我也试过:

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

But that doesn't work either.

但这也行不通。

回答by DarkDevine

You can use

您可以使用

hash( 'sha256', $string );

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

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

回答by Goran Miskovic

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

了Suhosin扩展增加了功能sha256(),甚至sha256_file(),到PHP核心。

With the extension installed:

安装扩展程序后:

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

bool(true)

回答by Wieszos

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

php标准库中没有这样的功能。改用hash函数。 http://php.net/manual/en/function.hash.php像:

$pass = hash('sha256', $_POST['password']);

回答by Berry Langerak

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

嗯。该功能不存在。如果要使用 SHA256 算法,请改用哈希