2014-12-24 104 views
17

我通过AppServ使用mcrypt_get_iv_size函数时发现问题。php - 致命错误:调用AppServ中的未定义函数mcrypt_get_iv_size()

我试图找到与解决问题有关的主题。

但是,我尝试将libmcrypt.dll下载到symtem32中,并通过从;extension=php_mcrypt.dll删除评论到extension=php_mcrypt.dll来编辑php.ini。然后重新启动apache。

不幸的是,重新加载页面后看到修改后的结果。

它仍然误差

Fatal error: Call to undefined function mcrypt_get_iv_size() in C:\AppServ\www\folder\index.php on line 36

函数包含以下内容:

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)); 
    } 
} 
+0

尝试从命令提示符运行PHP,这会给你任何错误,可能会发生在DLL加载,如缺少dll,缺少路径,混合c + +运行库等。 –

+0

如何做到这一点?你能建议吗?我检查所有的DLL,现在它存储在我的电脑中。所以,我不知道为什么它仍然是错误的。 – user2971638

+0

确保你在你的PATH中有php,然后打开命令提示符,输入:php,回车。看看是否有任何错误。 –

回答

1

在PHP-7的情况下:

sudo apt-get install mcrypt php7.1-mcrypt

49

在Ubuntu上,在PHP 5和Apache,你必须运行:

apt-get install php5-mcrypt 
php5enmod mcrypt 
service apache2 restart 

如果您使用的是PHP 7:

apt install php7.0-mcrypt 
+2

我不得不为所有这些命令添加'sudo'。 – usandfriends

1

我不得不对CentOS的7安装的mcrypt库针对上述问题的x86_64

下面是我所做的安装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 

与用户 '根' 或须藤

与此,无需添加 “扩展名= php_mcrypt.dll” 在php.ini文件

+0

找不到此连结? –

+0

现在有更高版本, [epel-release-7-6.noarch.rpm](http://dl.fedoraproject.org/pub/epel/7/x86_64/e/) – NBhat

相关问题