Fatal error: Call to undefined function mcrypt_enc

2019-01-16 17:35发布

NOTE: The libraries MCrypt support depend on have not been updated in years and MCrypt should no longer be considered a viable or secure method of encrypting data. What's more, MCrypt has been deprecated in PHP 5, and removed entirely in PHP 7. If you have any code that runs MCrypt you should refactor it to use a more modern encryption library.


Does anyone know why this error message: (Call to undefined function mcrypt_encrypt() ) displays when I run the following code below?

Am I missing some steps perhaps any setting in PHP I have to do before this code can work?

$key = 'password to (en/de)crypt';
$string = 'string to be encrypted';

$test = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
            $string, MCRYPT_MODE_CBC, md5(md5($key)));

标签: php mcrypt
17条回答
▲ chillily
2楼-- · 2019-01-16 18:15

You don't have the mcrypt library installed.

See http://www.php.net/manual/en/mcrypt.setup.php for more information.

If you are on shared hosting, you can ask your provider to install it.


In OSX you can easily install mcrypt via homebrew

brew install php54-mcrypt --without-homebrew-php

Then add this line to /etc/php.ini.

extension="/usr/local/Cellar/php54-mcrypt/5.4.24/mcrypt.so"
查看更多
我命由我不由天
3楼-- · 2019-01-16 18:15

One more thing: if you are serving PHP via a web server such as Apache, try restarting the web server. This will "reset" any PHP modules that might be present, activating the new configuration.

查看更多
混吃等死
4楼-- · 2019-01-16 18:18

On Linux Mint 17.1 Rebecca - Call to undefined function mcrypt_create_iv...

Solved by adding the following line to the php.ini

extension=mcrypt.so

After that a

service apache2 restart

solved it...

查看更多
不美不萌又怎样
5楼-- · 2019-01-16 18:20

If you are using php5-fpm do remeber to restart it, after installing mcrypt

service php5-fpm restart

查看更多
\"骚年 ilove
6楼-- · 2019-01-16 18:20

Check and install php5-mcrypt:

sudo apt-get install php5-mcrypt
查看更多
The star\"
7楼-- · 2019-01-16 18:22

For windows

;extension=php_mcrypt.dll to extension=php_mcrypt.dll 
 then restart your apache server

For Redhat

sudo yum install php55-mcrypt //if php5.5
sudo yum install php-mcrypt //if less than 5.4
sudo service httpd restart //if apache 2.4
sudo /etc/init.d/httpd restart //if apache 2.2 or less

For Ubuntu

sudo apt-get install php5-mcrypt
sudo service apache2 restart //if server not reloaded automatically 

Still not working?

sudo php5enmod mcrypt && sudo service apache2 restart

查看更多
登录 后发表回答