我试图获取加密cookie的值,但没有获得原始值。
if(!isset($_COOKIE['email'])):
Cookie::queue(Cookie::make('email', $uid, time() + (86400 * 30)));
endif;
Cookie已正确设置,但Cookie采用加密格式。如何获得原始价值。
我检索这样的Cookie" Cookie :: get(' email');"
但它采用加密格式。
答案 0 :(得分:0)
如果您正在开发一个开发项目,可以通过修改web的kernel.php文件(app / Http / Kernel.php)来禁用cookie加密。在“$ middlewareGroups”数组中,注释掉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,
],
评论它看起来像:
/**
* 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,
],
在生产环境中,您应该使用加密的Cookie。您可以使用以下内容解密它们:
\Crypt::decrypt(\Request::cookie(config('session.cookie')))