Page 1 of 1

setcookie Help

Posted: Fri Feb 20, 2009 7:28 am
by Enormity
I have code that I use on my websites to set cookies.

Code: Select all

setcookie("sid",$sid,time()+60*60*24*120,"/");
setcookie("uid",$r[0],time()+60*60*24*120,"/");
setcookie("name",$r[4],time()+60*60*24*120,"/");
I use this code on vgt-central.com and it works just fine. I am building a new website at shopvaluebuy.com and I am using the exact same code. However, for whatever reason, no cookies are being saved on the new website. I know the section that this code is in is being ran because right after this code is a database update call and a redirect. Both the update and redirect are taking place. Like I've said, I am using this exact same code on my other site and it works just fine. I'm going to go insane staring at this code... Can anyone give me any possible problems that I might have?

Thanks

Re: setcookie Help

Posted: Fri Feb 20, 2009 7:31 am
by mattpointblank
If you run any output to the browser (eg echo text) before the cookie is set, it'll fail. Also, do all three variables definitely exist?

Re: setcookie Help

Posted: Fri Feb 20, 2009 7:45 am
by Enormity
Hi, thanks for the response. There is no output before these calls, and all 3 variables do exist. The only thing that happens before these calls is a database query.

Re: setcookie Help

Posted: Fri Feb 20, 2009 8:42 am
by mattpointblank
Maybe you already have those cookies from somewhere else? The names are quite generic. Try installing Firebug for Firefox (along with Firecookie) so you can see in real time what's happening.

Re: setcookie Help

Posted: Fri Feb 20, 2009 11:30 am
by Enormity
Thanks again. I will get the addons and check that out. I do have the same cookie names for my other website, so I will also try removing those cookies and see if it works then.

Re: setcookie Help

Posted: Fri Feb 20, 2009 11:50 am
by Enormity
Wow, what an awesome add on. Thanks =) However, even though I cleared all cookies completely and had firebug running viewing the cookies, I didn't get anything from it. It didn't show that cookeis were even trying to be added. I looked at the error log and was also not shown anything regarding the cookies.