duanmu2941 2017-04-24 12:08
浏览 424

如何在laravel 5.4中获取加密cookie的原始值

I am try to get the value of encrypted cookies but not getting the original value.

if(!isset($_COOKIE['email'])):

    Cookie::queue(Cookie::make('email', $uid, time() + (86400 * 30)));          

endif;

The cookies are set properly but the cookies are in encrypted format. how to get its original value.

I retrieve cookies like this "Cookie::get('email');"

but it is in encrypted format.

  • 写回答

1条回答 默认 最新

  • duana1021 2017-09-07 15:52
    关注

    If you are working on a dev project, you can disable cookie encryption by modifying the kernel.php file (app/Http/Kernel.php) for web. In the "$middlewareGroups" array, comment out the EncryptCookiess::class line

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
    
        ],
    

    Comment it out to look like:

     /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            //\App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
    
        ],
    

    In a production environment, you should use encrypted cookies. You can decrypt them using something along the lines of:

    \Crypt::decrypt(\Request::cookie(config('session.cookie')))

    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表