php PHP7.1 和 Laravel 5.3:不推荐使用函数 mcrypt_get_iv_size()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41031076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:18:25  来源:igfitidea点击:

PHP7.1 and Laravel 5.3: Function mcrypt_get_iv_size() is deprecated

phplaravel

提问by nodeffect

I'm using Laravel 5.0 for all my projects. Yesterday, I've updated my PHP version from 7.0.x to version 7.1.0. Once updated, I tried opening my Laravel project and saw this message below:

我的所有项目都使用 Laravel 5.0。昨天,我已经将我的 PHP 版本从 7.0.x 更新到了 7.1.0 版本。更新后,我尝试打开我的 Laravel 项目并看到以下消息:

ErrorException in Encrypter.php line 303: 
Function mcrypt_get_iv_size() is deprecated

in Encrypter.php line 303
at HandleExceptions->handleError('8192', 'Function mcrypt_get_iv_size() is deprecated', 'C:\wamp64\www\project1\vendor\laravel\framework\src\Illuminate\Encryption\Encrypter.php', '303', array()) in Encrypter.php line 303

May I know how can I solve this ? Does using Laravel 5.3 solve the problem? I don't feel like updating my Laravel to 5.3 because it's a huge project and it will takes a long time to update. There are too much differences between these two versions. Lots of codes need to be modified.

我可以知道如何解决这个问题吗?使用 Laravel 5.3 能解决问题吗?我不想将我的 Laravel 更新到 5.3,因为这是一个庞大的项目,需要很长时间才能更新。这两个版本有太多的不同。很多代码需要修改。

Is there an easier way to solve this issue?

有没有更简单的方法来解决这个问题?

采纳答案by Benjamin Kohl

This error occurs because you probably have something other than AES-256-CBCas your cipher in your config/app.phpfile that depends on the mcrypt extension. Perhaps you are using MCRYPT_RIJNDAEL_256or MCRYPT_RIJNDAEL_128?

发生此错误是因为您的文件中可能有除AES-256-CBC密码之外的其他内容,该密码config/app.php取决于 mcrypt 扩展名。也许您正在使用MCRYPT_RIJNDAEL_256MCRYPT_RIJNDAEL_128

The best thing you can do without a full-blown Laravel upgrade is install the legacy encrypterand use it to update all your encrypted data to use the AES-256-CBC cipher which has been the default cipher since Laravel 5.1, I believe. Once you do this, you should be able to use PHP 7.1 for your Laravel application.

在没有全面升级 Laravel 的情况下,您可以做的最好的事情是安装旧版加密器并使用它来更新所有加密数据,以使用 AES-256-CBC 密码,我相信自 Laravel 5.1 以来一直是默认密码。完成此操作后,您应该能够在 Laravel 应用程序中使用 PHP 7.1。

回答by Quynh Le

In your config/app.phpconfiguration file, you should update the cipher to "AES-256-CBC"and set your key to a random 32 byte stringwhich may be securely generated using php artisan key:generate

在您的config/app.php配置文件中,您应该更新密码"AES-256-CBC"并将您的密钥设置为一个随机的 32 字节字符串,该字符串可以使用安全生成php artisan key:generate

回答by Debiprasad

Add this to the beginning of the config/app.php:

将此添加到 的开头config/app.php

error_reporting(E_ALL ^ E_DEPRECATED);

error_reporting(E_ALL ^ E_DEPRECATED);

Source: https://stackoverflow.com/a/42515505/225790

来源:https: //stackoverflow.com/a/42515505/225790

回答by prakash pokhrel

to solve this just change cipher in app.php from 'MCRYPT_RIJNDAEL_128' to 'AES-256-CBC'

要解决这个问题,只需将 app.php 中的密码从“MCRYPT_RIJNDAEL_128”更改为“AES-256-CBC”