mightywayne Posted January 25, 2008 Share Posted January 25, 2008 Hello, everyone. I run a game. Recently I've gotten complaints that peoples' cookies have been expiring much earlier than they should be, and some people can't log in at all. My cookies are set like this: $randomcookiethinger = rand(1, 999999999999999); setcookie(user, $randomcookiethinger, time()+1600, "", ""); The $randomcookiethinger is used to make sure they aren't editing cookie information. My check to see if the cookie expired is: if (!isset($_COOKIE["user"])) die('<font color="red"><b><big>Error:</big></b></font><font color="black"><br><br>You must log in first!'); Do you have ANY idea what could be wrong? Edit: Changed subject to conform to forum rules. Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/ Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 Yet you don't state how long they should last. 27 mins? You could try putting quotes around user when you set it and use "/" as your domain. Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-448960 Share on other sites More sharing options...
toplay Posted January 25, 2008 Share Posted January 25, 2008 +1600 is setting the cookie to expire in aprox. 26 minutes. If this is constantly being called, then it will keep setting the cookie ahead, but if only set once, then it will expire after 26 minutes. Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-448961 Share on other sites More sharing options...
mightywayne Posted January 25, 2008 Author Share Posted January 25, 2008 Oh, right, forgot to mention I tried the quotes thing. You know, I seriously think it might be the domain. I'll come back if it starts up again, thanks. Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-448978 Share on other sites More sharing options...
toplay Posted January 25, 2008 Share Posted January 25, 2008 You should not give empty string values for the fourth and fifth arguments to setcookie(). Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-449090 Share on other sites More sharing options...
mightywayne Posted January 26, 2008 Author Share Posted January 26, 2008 toplay, that's a great suggestion! I've tried it now (the bug still arose ) and hopefully I won't get anymore complaints. Gulp. ... however, if I do... I think it might have to do with the fact that I've .httaccess'd my website to remove the www. No matter what, you simply can't "get" to www. domain. I removed that due to complications in the forums and it's ugly anyway, is there a way to get around that when setting a cookie? Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-449411 Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 If you look at the cookie after it's set, does it show the www or not? Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-449413 Share on other sites More sharing options...
mightywayne Posted January 26, 2008 Author Share Posted January 26, 2008 It doesn't, but, all the cookies in that list don't. Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-449414 Share on other sites More sharing options...
toplay Posted January 26, 2008 Share Posted January 26, 2008 I hope you read the setcookie (link in my previous post) in the manual. 1) The code you show does not have quotes around the value "user". 2) Increase the time. 3) Set path to '/'. 4) Set domain (see manual). Example: $randomcookiethinger = rand(1, 999999999999999); setcookie('user', $randomcookiethinger, time()+21600, '/', '.domain_name.com'); Link to comment https://forums.phpfreaks.com/topic/87772-cookie-help/#findComment-449879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.