setcookie Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Enormity
Forum Newbie
Posts: 4
Joined: Fri Feb 20, 2009 7:23 am

setcookie Help

Post 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
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: setcookie Help

Post 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?
Enormity
Forum Newbie
Posts: 4
Joined: Fri Feb 20, 2009 7:23 am

Re: setcookie Help

Post 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.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: setcookie Help

Post 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.
Enormity
Forum Newbie
Posts: 4
Joined: Fri Feb 20, 2009 7:23 am

Re: setcookie Help

Post 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.
Enormity
Forum Newbie
Posts: 4
Joined: Fri Feb 20, 2009 7:23 am

Re: setcookie Help

Post 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.
Post Reply