致命错误:调用未定义的函数 mcrypt_encrypt()

发布于 2024-08-28 01:21:40 字数 551 浏览 10 评论 0原文

注意: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

岁月苍老的讽刺 2024-09-04 01:21:40

如果您最近更新到 ubuntu 14.04,这里是解决此问题的方法:

$ sudo mv /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
$ sudo php5enmod mcrypt
$ sudo service apache2 restart

If you have recently updated to ubuntu 14.04 here is the fix to this problem:

$ sudo mv /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
$ sudo php5enmod mcrypt
$ sudo service apache2 restart
一口甜 2024-09-04 01:21:40

对于 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 the php_mcrypt.dll extension by removing the ;, i.e. changing:

;extension=php_mcrypt.dll to extension=php_mcrypt.dll

£噩梦荏苒 2024-09-04 01:21:40

对于 Windows

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

对于 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

对于 Ubuntu

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

仍然无法工作?

sudo php5enmod mcrypt && sudo 服务 apache2 重新启动

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

离不开的别离 2024-09-04 01:21:40

如果您使用 PHP 7.2 或更高版本:

此函数在 PHP 7.1.0 中已弃用,并在 PHP 7.2.0 中已删除。

来源: http://php.net/manual/en/function.mcrypt-encrypt .php

所以你必须更换php代码并找到没有mcrypt的解决方案。

或者,我刚刚发现,您仍然可以在 PHP 7.2.0 中使用 mcrypt,但您必须将其安装为 PHP 扩展社区库。 (https://pecl.php.net/)

在 Debian/Ubuntu Linux 发行版上:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install php7.2-dev
sudo apt-get -y install libmcrypt-dev

那么:

sudo pecl install mcrypt-1.0.1

来源: < 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:

This function was DEPRECATED in PHP 7.1.0, and REMOVED in PHP 7.2.0.

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:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install php7.2-dev
sudo apt-get -y install libmcrypt-dev

then:

sudo pecl install mcrypt-1.0.1

Source: https://www.techrepublic.com/article/how-to-install-mcrypt-for-php-7-2/

夕嗳→ 2024-09-04 01:21:40

您没有安装 mcrypt 库。

请参阅http://www.php.net/manual/en/mcrypt.setup。 php 了解更多信息。

如果您使用共享主机,您可以要求您的提供商安装它。


在 OSX 中,您可以通过 homebrew 轻松安装 mcrypt

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

然后将此行添加到 /etc/php.ini。

extension="/usr/local/Cellar/php54-mcrypt/5.4.24/mcrypt.so"

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"
—━☆沉默づ 2024-09-04 01:21:40

在Ubuntu下我遇到了问题并解决了

$ sudo apt-get install php5-mcrypt
$ sudo service apache2 reload

Under Ubuntu I had the problem and solved it with

$ sudo apt-get install php5-mcrypt
$ sudo service apache2 reload
囚我心虐我身 2024-09-04 01:21:40

在 ubuntu 14.10 上:

安装模块 mcrypt

sudo apt install php5-mcrypt

在 apache2 上启用模块 mcrypt

sudo a2enmod mcrypt

重新加载模块配置

sudo service apache2 restart

On ubuntu 14.10 :

Install module mcrypt

sudo apt install php5-mcrypt

Enable module mcrypt on apache2

sudo a2enmod mcrypt

Reload module configuration

sudo service apache2 restart
小嗷兮 2024-09-04 01:21:40

在 Linux Mint 17.1 Rebecca 上 - 调用未定义的函数 mcrypt_create_iv...

通过将以下行添加到 php.ini

extension=mcrypt.so

解决

service apache2 restart

了此问题...

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...

御弟哥哥 2024-09-04 01:21:40

对于缺少 mcrypt 的 PHP 7 版本,我也遇到了同样的问题。

这对我有用。

sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade
sudo service apache2 restart (if needed)

I had the same issue for PHP 7 version of missing mcrypt.

This worked for me.

sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade
sudo service apache2 restart (if needed)
一身骄傲 2024-09-04 01:21:40

是否启用了 mcrypt?您可以使用 phpinfo() 来查看是否这是。

Is mcrypt enabled? You can use phpinfo() to see if it is.

辞旧 2024-09-04 01:21:40

还有一件事:如果您通过 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.

南七夏 2024-09-04 01:21:40

假设您使用的是 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 just sudo 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.

メ斷腸人バ 2024-09-04 01:21:40

如果您使用 php5-fpm 请记住重新启动它,安装 mcrypt

服务 php5-fpm restart后

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

service php5-fpm restart

Saygoodbye 2024-09-04 01:21:40

如果您使用 ubuntu 14.04,这里是解决此问题的方法:

首先检查 php5-mcryp 是否已安装 apt-get install php5-mcrypt

如果已安装,只需运行这两个命令或安装并运行这两个命令

$ sudo php5enmod mcrypt
$ sudo service apache2 restart

我希望它会起作用。

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

$ sudo php5enmod mcrypt
$ sudo service apache2 restart

I hope it will work.

朮生 2024-09-04 01:21:40

我的环境: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!

棒棒糖 2024-09-04 01:21:40

在 Ubuntu 18.04 和 php7.0 中

$ sudo apt-get install php7.0-mcrypt

$ sudo systemctl reload apache2

In Ubuntu 18.04, and for php7.0

$ sudo apt-get install php7.0-mcrypt

$ sudo systemctl reload apache2
缱绻入梦 2024-09-04 01:21:40

对于基于 Linux (Fedora) 的情况,

yum -y install php-mcrypt

通过将“extension=mcrypt.so”添加到 PHP.ini 来启用该模块。 (/etc/php.ini)

systemctl restart httpd.service

完成!

for Linux based (Fedora)

yum -y install php-mcrypt

Enable the module by adding: 'extension=mcrypt.so' to PHP.ini. (/etc/php.ini)

systemctl restart httpd.service

Done!

逆蝶 2024-09-04 01:21:40

对我来说,它有助于卸载 mcrypt:

sudo apt-get purge php5-mcrypt

并简单地重新安装它:

sudo apt-get install php5-mcrypt

并且不要忘记如上所述重新启动 apache。

不知道为什么以及如何在我的情况下有所不同(使用配置了 php55 的虚拟机),但这也许会对其他人有所帮助。我在使用其他一些模块(例如 xcache)时也遇到了这个问题...

For me it helped to uninstall mcrypt with:

sudo apt-get purge php5-mcrypt

and simply reinstall it:

sudo apt-get install php5-mcrypt

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...

望喜 2024-09-04 01:21:40

检查并安装 php5-mcrypt:

sudo apt-get install php5-mcrypt

Check and install php5-mcrypt:

sudo apt-get install php5-mcrypt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文