问题
I found a problem when I use mcrypt_get_iv_size function via AppServ.
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.
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
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));
}
}
回答1:
in case of php-7:
sudo apt-get install mcrypt php7.1-mcrypt
回答2:
On Ubuntu, with PHP 5 and Apache, you have to run:
apt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart
If you are using PHP 7:
apt install php7.0-mcrypt
回答3:
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.
It's seems like php_mcrypt.dll
extension is not loaded.
回答4:
I had to install the mcrypt libraries on CentOS 7 x86_64 for the above problem.
Here is what I did to install php-mcrypt & libmcrypt dependencies.
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
with this, no need to add "extension=php_mcrypt.dll" in php.ini file
来源:https://stackoverflow.com/questions/27633584/php-fatal-error-call-to-undefined-function-mcrypt-get-iv-size-in-appserv