How to read laravel_session cookies stored in browser cookie memory on client side?

I have an app for laravel and angular, I would like to read cookies from client side to server, but I cannot read it. So can someone tell me how can I read the cookies.

+3


source to share


3 answers


The default laravel_session cookie is HTTP_ONLY , so you cannot manipulate them with js. But you can change this flag in your_project\config\session.php

by adding



'http_only' => false

      

+1


source


As mentioned by @AlexSlipknot. You need to change the setting to allow JavaScript to access cookies.

Change the value to false in the file config/session.php

/*
|--------------------------------------------------------------------------
| HTTP Access Only
|--------------------------------------------------------------------------
|
| Setting this value to true will prevent JavaScript from accessing the
| value of the cookie and the cookie will only be accessible through
| the HTTP protocol. You are free to modify this option if needed.
|
*/

'http_only' => true,

      



Also note that laravel cookies are encrypted and decrypted on the fly by the application. Even if you read the cookie, it will be the encrypted value. If you need to access and modify some non-encrypted cookies, you need to add these encryption cookies besides the list.

You can add cookies to skip encryption on the file app/Http/Middleware/EncryptCookies.php

protected $except = [
    //
];

      

+1


source


I just posted an answer to a related question that I think might also be relevant, since I believe you are dealing with client-side cookies on the server here: How to work with cookies in Laravel 5.2

-1


source







All Articles