View Full Version : Cookie gets deleted when the browser closes.

09-24-2005, 12:06 PM
Whenever I close my browser the cookie gets deleted for some reason. Here's the code I use to set the cookie:

setcookie('sitename', "$uname2,$pword2", time()+2147483647);

I'm not using sessions or anything so I don't understand why this is happening. It happens in Firefox and IE so it's not browser related like I thought. I figured there must be a stupid mistake with how I'm setting it.

If you need more code let me know, but that should be the only relevant part pertaining to cookies.



I found the problem myself already. On my home install of apache/php the session.cookie_lifetime was set to 0. It worked fine on my remote server so I figured it had something to do with my apache/php configuration.

I didn't see a way to close this so I just added the solution for anyone else that searchs for the same problem.

09-24-2005, 03:23 PM
I think its becuase of the ammount of time you are trying to set the cookie for (68 years). I usually set cookies for no more than a year.... I always use an exact value by doing multiplication:

$cookietime = time()+(60*60*24*365);

this always works fine, i did try multiplying this by 100 though as a test, and I encountered the same problem as you.