php - 致命错误:调用 AppServ 中未定义的函数 mcrypt_get_iv_size()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27633584/
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
php - Fatal error: Call to undefined function mcrypt_get_iv_size() in AppServ
提问by user2971638
I found a problem when I use mcrypt_get_iv_size function via AppServ.
我在通过AppServ使用 mcrypt_get_iv_size 函数时发现了一个问题。
I try to find a topic that related to solved a problem.
我试图找到一个与解决问题相关的主题。
However, I try yo download libmcrypt.dll into symtem32 and edit php.ini by removing a comment from ;extension=php_mcrypt.dll
to extension=php_mcrypt.dll
. Then restart apache.
但是,我尝试将 libmcrypt.dll 下载到 symtem32 并通过从;extension=php_mcrypt.dll
to 中删除注释来编辑 php.ini extension=php_mcrypt.dll
。然后重启apache。
Unfortunately, after reload a page to see a result after modify.
不幸的是,在重新加载页面后看到修改后的结果。
It still error as
它仍然错误为
Fatal error: Call to undefined function mcrypt_get_iv_size() in C:\AppServ\www\folder\index.php on line 36
致命错误:在第 36 行调用 C:\AppServ\www\folder\index.php 中未定义的函数 mcrypt_get_iv_size()
A function contains following:
一个函数包含以下内容:
class Encryption {
var $skey = "SuPerEncKey2010"; // you can change it
public function safe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
public function safe_b64decode($string) {
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
return base64_decode($data);
}
public function encode($value){
if(!$value){return false;}
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv);
return trim($this->safe_b64encode($crypttext));
}
public function decode($value){
if(!$value){return false;}
$crypttext = $this->safe_b64decode($value);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv);
return strtolower(trim($decrypttext));
}
}
采纳答案by Vikas Chauhan
in case of php-7:
在 php-7 的情况下:
sudo apt-get install mcrypt php7.1-mcrypt
须藤 apt-get 安装 mcrypt php7.1-mcrypt
回答by marcomoser
On Ubuntu, with PHP 5 and Apache, you have to run:
在 Ubuntu 上,使用 PHP 5 和 Apache,您必须运行:
apt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart
If you are using PHP 7:
如果您使用的是 PHP 7:
apt install php7.0-mcrypt
回答by Mark Shevchenko
http://php.net/manual/en/mcrypt.requirements.php
http://php.net/manual/en/mcrypt.requirements.php
mcrypt is already build in for PHP 5.3.x for Windows, so you don't need to install libmcrypt.dll
on the your server.
mcrypt 已经内置于适用于 Windows 的 PHP 5.3.x,因此您无需libmcrypt.dll
在服务器上安装。
It's seems like php_mcrypt.dll
extension is not loaded.
好像php_mcrypt.dll
没有加载扩展。
回答by NBhat
I had to install the mcrypt libraries on CentOS 7 x86_64for the above problem.
对于上述问题,我必须在CentOS 7 x86_64上安装 mcrypt 库。
Here is what I did to install php-mcrypt & libmcrypt dependencies.
这是我为安装 php-mcrypt 和 libmcrypt 依赖项所做的工作。
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -ivh epel-release-7-5.noarch.rpm
yum install --enablerepo="epel" php-mcrypt
with user 'root' or sudo
使用用户 'root' 或 sudo
with this, no need to add "extension=php_mcrypt.dll" in php.ini file
有了这个,不需要在 php.ini 文件中添加“extension=php_mcrypt.dll”