PHP mcrypt Legacy Guide and Modern Alternatives

mcrypt is legacy: use Sodium or OpenSSL

The mcrypt extension was deprecated in PHP 7.1 and removed from PHP core in PHP 7.2. New PHP applications should use Sodium where suitable or OpenSSL for supported cryptographic operations.

$message = 'Private message';
$key = sodium_crypto_secretbox_keygen();
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$ciphertext = sodium_crypto_secretbox($message, $nonce, $key);

The mcrypt installation material below is retained only as historical/migration reference for old PHP environments.

Historical reference: The material below documents older PHP environments where mcrypt was installed separately. It is not a setup guide for current PHP.
Removed from PHP core: mcrypt was deprecated in PHP 7.1 and removed in PHP 7.2. The sections below are historical reference only.

Enabling mcrypt setting inside PHP.INI

Inside your php.ini file search for the line
;extension=php_mcrypt.dll
Change this line to
extension=php_mcrypt.dll

Loading the extension

Inside your php extension directory ( where all other extension dll files are stored) your dll file should be there . like this
mcrypt dll file inside extension directory
If it is not there then you have to install the extension. Go to control panel

Control Panel > Programs > Programs and Features
Uninstall or change a program

Select PHP and go for Change
adding mcrypt extension

Checking php installation

We can use phpinfo() function to know the settings of our PHP installation. If mcrypt is available then we will get this while using phpinfo() .
php info on  mcrypt support

For Linux or LAMP

Add the extension by adding this line.
extension=mcrypt.so
After this you have to restart your web server.

Checking extension status and function

We can use function_exists() to check of mycrypt functions are available or not. Similarly we can check status of extension by using extension_loaded(). Here is a sample code to know the status of mcrypt support in your PHP installation.
<?Php
if(function_exists('mcrypt_create_iv')){
echo "<br>mcrypt_create_iv function support is available ";
}else{
echo "<br>mcrypt_create_iv function support is NOT available ";
}

if (extension_loaded('mcrypt')) {
echo "<br>mcrypt support is loaded ";
}else{
echo "<br>mcrypt support is NOT loaded ";
}
?>
The output of above code will tell about the mrypt support in our PHP installation.


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer