Khanetor
Khanetor

Reputation: 12302

Play with Play cookie session

When I set a value to session (cookie session), I can see that value from the client like below

firefox request cookies

However, when I try to get the cookie with javascript document.cookie, this is all I get

enter image description here

How can I get the PLAY_SESSION cookie?

Upvotes: 0

Views: 1227

Answers (1)

Kris
Kris

Reputation: 4823

You can't get the session cookie in the JavaScript of your browser. For security reasons it's set to http-only.

If you just want to persist some small data between requests you can set your own cookie in the response of an action. Just set the http-only flag to false:

response().setCookie(
    "theme",        // name
    "blue",         // value
    3600,           // maximum age
    "/some/path",   // path
    ".example.com", // domain
    false,          // secure
    false           // http only
);

With the http-only flag set to false you can access your cookie from your JavaScript within the browser.

Upvotes: 3

Related Questions