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')))

    评论

报告相同问题?