致命错误:调用未定义的函数 mcrypt_encrypt()
注意: MCrypt 支持所依赖的库已经多年没有更新,MCrypt 不应再被视为加密数据的可行或安全方法。此外,MCrypt 在 PHP 5 中已被弃用,并在 PHP 7 中被完全删除。如果您有任何运行 MCrypt 的代码,您应该重构它以使用更现代的加密库。
有谁知道为什么当我运行下面的代码时显示此错误消息:(Call to undefined function mcrypt_encrypt() )
?
我是否缺少一些步骤,也许是在 PHP 中我必须执行的任何设置才能使此代码正常工作?
$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)));
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)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
如果您最近更新到 ubuntu 14.04,这里是解决此问题的方法:
If you have recently updated to ubuntu 14.04 here is the fix to this problem:
对于 PHP 版本 5.2.8,对我有用的是打开
php.ini
并通过删除;
来允许php_mcrypt.dll
扩展>,即将:;extension=php_mcrypt.dll
更改为extension=php_mcrypt.dll
What had worked for me with PHP version 5.2.8, was to open up
php.ini
and allow thephp_mcrypt.dll
extension by removing the;
, i.e. changing:;extension=php_mcrypt.dll
toextension=php_mcrypt.dll
对于 Windows
对于 Redhat
对于 Ubuntu
仍然无法工作?
For windows
For Redhat
For Ubuntu
Still not working?
如果您使用 PHP 7.2 或更高版本:
来源: http://php.net/manual/en/function.mcrypt-encrypt .php
所以你必须更换php代码并找到没有mcrypt的解决方案。
或者,我刚刚发现,您仍然可以在 PHP 7.2.0 中使用 mcrypt,但您必须将其安装为 PHP 扩展社区库。 (https://pecl.php.net/)
在 Debian/Ubuntu Linux 发行版上:
那么:
来源: < a href="https://www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/" rel="noreferrer">https://www.techrepublic.com/article /如何安装-mcrypt-for-php-7-2/
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/
您没有安装 mcrypt 库。
请参阅http://www.php.net/manual/en/mcrypt.setup。 php 了解更多信息。
如果您使用共享主机,您可以要求您的提供商安装它。
在 OSX 中,您可以通过 homebrew 轻松安装 mcrypt
然后将此行添加到 /etc/php.ini。
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
Then add this line to /etc/php.ini.
在Ubuntu下我遇到了问题并解决了
Under Ubuntu I had the problem and solved it with
在 ubuntu 14.10 上:
安装模块 mcrypt
在 apache2 上启用模块 mcrypt
重新加载模块配置
On ubuntu 14.10 :
Install module mcrypt
Enable module mcrypt on apache2
Reload module configuration
在 Linux Mint 17.1 Rebecca 上 - 调用未定义的函数 mcrypt_create_iv...
通过将以下行添加到 php.ini
解决
了此问题...
On Linux Mint 17.1 Rebecca - Call to undefined function mcrypt_create_iv...
Solved by adding the following line to the php.ini
After that a
solved it...
对于缺少 mcrypt 的 PHP 7 版本,我也遇到了同样的问题。
这对我有用。
I had the same issue for PHP 7 version of missing mcrypt.
This worked for me.
是否启用了 mcrypt?您可以使用
phpinfo()
来查看是否这是。Is mcrypt enabled? You can use
phpinfo()
to see if it is.还有一件事:如果您通过 Web 服务器(例如 Apache)提供 PHP 服务,请尝试重新启动 Web 服务器。这将“重置”可能存在的任何 PHP 模块,激活新配置。
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.
假设您使用的是 debian linux(我使用的是 Linux mint 12,问题出在我通过 ssh 进入的 Ubuntu 12.04.1 LTS 服务器上。)
我建议您采纳 @dkamins 的建议,并确保您已安装 mcrypt 并在 php5 安装上处于活动状态。使用“sudo apt-get install php5-mcrypt”进行安装。我的笔记如下。
使用 PHP 版本
PHP Version 5.3.10-1ubuntu3.4
,如果您按照 @John Conde 的建议打开 phpinfo(),您可以通过在 Web 服务器上创建测试文件来完成此操作(例如创建状态页面 testphp.ini)。 我发现在浏览器中打开状态页面时,状态页面上不存在启用或禁用状态。然后,当我打开 @Anthony Forloney 提到的 php.ini 文件时,考虑取消注释
;extension=php_mcrypt.dll 到 extension=php_mcrypt.dll
我来回切换并重新启动 Apache(我'我正在运行 Apache2,您可以使用
sudo /etc/init.d/apache2 restart
在我的设置中重新启动,或者当您在该目录中时,只需sudo restart
我相信)有变化和没有变化,但都行不通。我采纳了 @dkamins 的建议,并使用“sudo apt-get install php5-mcrypt”来安装软件包,然后按照上面的方式重新启动 apache。然后我的错误消失了,我的应用程序运行良好。
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.
如果您使用 php5-fpm 请记住重新启动它,安装 mcrypt
服务 php5-fpm restart后
If you are using php5-fpm do remeber to restart it, after installing mcrypt
service php5-fpm restart
如果您使用 ubuntu 14.04,这里是解决此问题的方法:
首先检查 php5-mcryp 是否已安装
apt-get install php5-mcrypt
如果已安装,只需运行这两个命令或安装并运行这两个命令
我希望它会起作用。
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.
我的环境:Windows 10、Xampp 控制面板 v3.2.4、PHP 7.3.2
第 1 步:从此处下载适合您系统的版本:https://pecl.php.net/package/mcrypt/1.0.3/windows
步骤2:解压并复制 php_mcrypt.dll 文件到 .. /xampp/php/ext/
步骤 3:打开 ../xampp/php/php.ini 文件并添加一行
extension=php_mcrypt.dll
步骤 4:重新启动 apache,完成!
My Environment: Windows 10, Xampp Control Panel v3.2.4, PHP 7.3.2
Step-1: Download a suitable version for your system from here: https://pecl.php.net/package/mcrypt/1.0.3/windows
Step-2: Unzip and copy php_mcrypt.dll file to ../xampp/php/ext/
Step-3: Open ../xampp/php/php.ini file and add a line
extension=php_mcrypt.dll
Step-4: Restart apache, DONE!
在 Ubuntu 18.04 和 php7.0 中
In Ubuntu 18.04, and for php7.0
对于基于 Linux (Fedora) 的情况,
通过将“extension=mcrypt.so”添加到 PHP.ini 来启用该模块。 (/etc/php.ini)
完成!
for Linux based (Fedora)
Enable the module by adding: 'extension=mcrypt.so' to PHP.ini. (/etc/php.ini)
Done!
对我来说,它有助于卸载 mcrypt:
并简单地重新安装它:
并且不要忘记如上所述重新启动 apache。
不知道为什么以及如何在我的情况下有所不同(使用配置了 php55 的虚拟机),但这也许会对其他人有所帮助。我在使用其他一些模块(例如 xcache)时也遇到了这个问题...
For me it helped to uninstall mcrypt with:
and simply reinstall it:
and dont forget to restart apache as described above.
Dont know why and how this was different in my case (using a vm with provisioned php55), but maybe this will help someone else. I also had this problem with some other modules like xcache...
检查并安装 php5-mcrypt:
Check and install php5-mcrypt: