Larware
Larware

Reputation: 51

Laravel same cookie values

I have problem with setting cookies. After I redirect I want to put some data in cookies for client side and its working but problem is cookie values.

I use that form to set cookies:

return redirect($url)
                ->withCookie(cookie('cookieA', 'valueA'))
                ->withCookie(cookie('cookieB', 'valueB'));

And after that client redirects to $url and when I sneak into cookies I see these values:

XSRF-TOKEN : eyJpdiI6ImxEUko5T0EzVG1cLzRLa09sQk0rZHdB...
cookieA : eyJpdiI6ImxEUko5T0EzVG1cLzRLa09sQk0rZHdB...
cookieB : eyJpdiI6ImxEUko5T0EzVG1cLzRLa09sQk0rZHdB...

laravel_session : L7hsdCD6hQBvX1FDM2biFZ3As...

It seems that somehow Laravel changes cookie value.

I have tried :

Cookie::queue('cookieA', 'valueA', 45000);
withCookie(cookie()->forever('cookieA', 'valueA'));

still same result

Upvotes: 0

Views: 1279

Answers (3)

a.mohamadi
a.mohamadi

Reputation: 1

you can use setcookie function it set cookie without encrypting

setcookie('CookieName', 'CookieValue', 'CookieLifeTime','CookieRootDirectory');

Upvotes: 0

Larware
Larware

Reputation: 51

This problem solved my problem:

Unencrypted cookie in Laravel

in App\Http\Middleware\EncryptCookies i added my cookies names in protected $except = [];

now its working c:

Upvotes: 1

user8034901
user8034901

Reputation:

Cookies set via Laravel are encrypted/signed. If you use

$cookieAValue = Cookie::get('cookieA');

in Laravel, you'll get the actual value of the cookie. If you use your browser's devtools to view the cookie you'll see the encrypted value.

https://laravel.com/docs/5.7/requests#cookies

Upvotes: 1

Related Questions