The cookie problem...

Canada
March 3, 2007 9:53pm CST
To all my regular friends who think this is going to be about cookies, such as chocolate chip cookies, etc; sorry but this post is going to put you to sleep... My problem is this, I have a problem with the syntax of setting up a cookie. What happens is this, I set a cookie at mysite.com/members using the following: setcookie(theuser, myusername, $inOneHour,'/','.mysite.com'); I can access this cookie from anywhere in mysite.com/members but it doesn't work anywhere else. Can someone point out what I'm doing wrong? Thanks... BTW, Best response goes to the first person that helps me to get this working. Cheers...
1 person likes this
2 responses
• United States
4 Mar 07
Generaly a cookie can only be read by the directory that set the cookie and all subdirectories; however, if you want the cookie readable by the whole domain set the path value to "/". As far as I know this is the only way your whole site can read the cookie.
• Canada
4 Mar 07
Thanks... I think I just figured out the problem, and a work around, at probably the same time you were typing your reply ;) It turns out that it was working at the domain root level. I placed the code in a new php file and it worked. The page I wanted it for is one like mysite.com/username like which is used here and on myspace... but..after a little work around, its working now...
• United States
4 Mar 07
Good to know! After years of dealing with PHP I think that cookies are the toughest aspect of the language. Maybe they will have better support in PHP6 lol.
• Uruguay
6 Apr 07
cookies are the toughest aspect of the language??? lol my apologies but this is just way too bizarre not to be laughing at... oh and just as a curiosity, cookies are not even part of the php language, they're part of the http spec, php just have some functions to deal with them.
• United States
5 Mar 07
Gosh, if this was about molasses cookies - I could help you out --- but computer cookies elude me.
• United States
9 Apr 07
I just baked some chocolate chip cookies - want some? Maybe it won't help your problem but you will feel better! :)