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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.