efficiencyIsBliss
efficiencyIsBliss

Reputation: 3093

Basic issue with setting HTTP cookies

I'd like to set an HTTP cookie for my users, in order to not bother them with having to log in every time.

What I want to know is this: if I set the cookie at a page other than the homepage for my website, then will that cookie be available when the user comes to my homepage the next time?

More generally, is it the case that I can set the cookie at any page of my website, and the cookie will be available to me whenever I want?

Thanks!

Upvotes: 0

Views: 58

Answers (3)

Brandon Smith
Brandon Smith

Reputation: 11

Yes - once you set a cookie it will be accessible from the server as long as it is stored in the user's browser (hasn't expired or been deleted).

Upvotes: 1

zneak
zneak

Reputation: 138171

Cookies can be configured to be available on specific subdomains, specific paths and specific protocols (HTTPS only, for instance). Without you telling which language you're using, it's hard to tell the default behavior of your local Set-Cookie function, but I believe that most often, the default behavior is to make the cookie available to all subdomains and all paths.

So yes, if you set a cookie on a random page, it should be available to the home page, too.

Upvotes: 1

efficiencyIsBliss
efficiencyIsBliss

Reputation: 3093

I found that if the cookie is being set via Javascript, then this can be determined via a simple parameter.

The example JS code (from here) sets a cookie, that is available across the site

    $.cookie('the_cookie', 'the_value', {path: '/'});

Upvotes: 0

Related Questions