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)));
If you are using PHP 7.2 or up:
source: http://php.net/manual/en/function.mcrypt-encrypt.php
So you have to replace the php code and find a solution without mcrypt.
Or, I just found out, you can STILL use mcrypt in PHP 7.2.0, but you have to install it as a PHP Extension Community Library. (https://pecl.php.net/)
On Debian/Ubuntu Linux distros:
then:
Source: https://www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/
If you have recently updated to ubuntu 14.04 here is the fix to this problem:
Under Ubuntu I had the problem and solved it with
If you using ubuntu 14.04 here is the fix to this problem:
First check php5-mcryp is already installed
apt-get install php5-mcrypt
If installed, just run this two command or install and run this two command
I hope it will work.
Assuming you are using debian linux (I'm using Linux mint 12, problem was on Ubuntu 12.04.1 LTS server I ssh'ed into.)
I suggest taking @dkamins advice and making sure you have mcrypt installed and active on your php5 install. Use "sudo apt-get install php5-mcrypt" to install. My notes below.
Using PHP version
PHP Version 5.3.10-1ubuntu3.4
, if you open phpinfo() as suggested by @John Conde, which you do by creating test file on web server (e.g. create status page testphp.php with just the contents "" anywhere accessible on the server via browser)I found no presence of enabled or disabled status on the status page when opened in browser. When I then opened the php.ini file, mentioned by @Anthony Forloney, thinking to uncomment
;extension=php_mcrypt.dll to extension=php_mcrypt.dll
I toggled that back and forth and restarted Apache (I'm running Apache2 and you can restart in my setup with
sudo /etc/init.d/apache2 restart
or when you are in that directory justsudo restart
I believe) with change and without change but all no go. I took @dkamins advice and went to install the package with "sudo apt-get install php5-mcrypt" and then restarted apache as above. Then my error was gone and my application worked fine.I had the same issue for PHP 7 version of missing mcrypt.
This worked for me.