Jump to content

Cookies in folders...


ojeffery
 Share

Recommended Posts

Hi all,I've set a cookie, which is working fine, but it's only accessable from the folder of the page I set it in (in this case the admin folder). I didn't specifically tell it to set in that folder, but it only works on files in there. I need to be able to access it from all folders in the site. What am I doing wrong? :) Cheers, Oli.

Link to comment
Share on other sites

If you don't specify things like a domain and a path for the cookie, the server will set those properties. So the server is probably set up to default to "maximum security" mode or something. Just set the domain and path yourself. You can check the reference for setcookie here:http://www.php.net/manual/en/function.setcookie.phpSee the notes on that page. So, if you want a cookie that expires in an hour, available on all subdomains and all paths on the server, then it would be like this:setcookie("cookiename", "value", time() + (60 * 60), "/", ".domain.com");Make sure to put the dot before your domain to make it apply for all subdomains, .domain.com will be available on domain.com, www.domain.com, test.domain.com, etc.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...