Page 1 of 1

Cookie doesn't set on server

Posted: Thu Nov 03, 2011 8:55 am
by Mr X
Hello to all. Yesterday I came across an issue where I can't execute cookie set properly on the server. It works locally though without no problems. The domain's path is "/tmp" for session_path. Here's the code. Thanks for comments:

Code: Select all


if (!isset($_COOKIE['TestCookie'])) { 
$vote_com2 =  mysqli_query($connect,"UPDATE news SET up = '".$upv."' WHERE news_id = '$idn'" );
setcookie("TestCookie", $idn, time()+3600,"/",".mydomain.net"); 
}


Re: Cookie doesn't set on server

Posted: Thu Nov 03, 2011 3:38 pm
by pickle
This may be obvious, but is the code being run on a subdomain of "mydomain.net" (which I assume is just a dummy domain for the purposes of posting here)?

Re: Cookie doesn't set on server

Posted: Thu Nov 03, 2011 5:22 pm
by Mr X
Hi - yes it's a dummy domain. The cookie runs on the main domain i.e. ( not on subdomain ). For now I've referred to using $_SESSION instead - helps for as long as the browser is on. But cookie is the proper way for this feature..

Re: Cookie doesn't set on server

Posted: Thu Nov 03, 2011 5:29 pm
by pickle
Is the time() correct? If time() on the server is an hour or more behind your computer's clock, it would be invalid.

There's an extension you can get for Firefox that captures http headers (which is what is used to set cookies). You can use that to check if the proper headers are being sent to your computer.

Re: Cookie doesn't set on server

Posted: Thu Nov 03, 2011 5:38 pm
by Mr X
I see - I'm gonna check the time out and I'll mind the extension. Thanks a lot. Speak soon..

Re: Cookie doesn't set on server

Posted: Thu Nov 03, 2011 6:11 pm
by Mr X
The time of the server is Chicago IL that is about 4h difference between my country...

Re: Cookie doesn't set on server

Posted: Fri Nov 04, 2011 9:44 am
by pickle
So your best bet is to use $_SESSION, or have a cookie with a longer expiry, or set it to 0, which kills the cookie when the browser quits.

Re: Cookie doesn't set on server

Posted: Fri Nov 04, 2011 7:34 pm
by Mr X
Sure - now I now what the issue is about - thanks a lot !