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.
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 = [
//
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With