Jump to content

Cookie help


mightywayne

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.