Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read laravel_session cookies saved in cookie memory of browser in client side?

I have an laravel and angular based application, I would like to read cookies from client to server side, But i can't read it. So can any one tell me how could I read the cookies.

like image 479
parthi Avatar asked Oct 14 '25 16:10

parthi


1 Answers

By default, Laravel enables Browser's HTTP-Only feature, meaning the cookie is not accessible from JavaScript.

But that can be turned off,
by changing the default-value to false in the config/session.php file:

/*
|--------------------------------------------------------------------------
| 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 would be the encrypted value. If you need to access and modify certain cookies without encryption, then you need to add those cookies to the encryption except list.

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

protected $except = [
    //
];
like image 65
Sandeesh Avatar answered Oct 17 '25 05:10

Sandeesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!