Jump to content

[SOLVED] problems with cookies


ohdang888

Recommended Posts

this is sorta confusing to say, but i gotta try.

 

I have a "brain.php" located in the "folder" include from the root directory. Every file on my server includes this file, and it sets COOKIES of hashed keys to recongize and automatically log in users.

 

When i go to logout.php, located in the root directory,  it destorys the cookies. Now they must log in again to be recongized as a logged in user.

 

When i go to logout.php, it successfully destorys my session and cookies, and redirects me to index.php of the root directory. Any file in the root directory says i'm logged out. That's good, that's what i want.

 

 

BUT, when i go to another directory, like "/testing" or "/beta", which includes the same brain.php file, all files in other directories automatically log me in....in other words, this is my question:

 

It seems as though the cookies of the root directory are just being deleted, even though i am setting the same cookie anywhere. Are cookie's url sensitive? How would i destory all cookies for the entire domain?

 

this is my cookie destorying code:

 

$_SESSION = array();

setcookie("key1", NULL,time() + 1);

setcookie("key2", NULL,time() + 1);

 

Link to comment
https://forums.phpfreaks.com/topic/155136-solved-problems-with-cookies/
Share on other sites

The 4th setcookie() parameter is the path. Without it, each setcookie() in a different path is setting a different cookie.

 

To log someone out, you should only depend on a value stored on your server to tell you what the actual in/out status is. The cookie should only identify who they are. Doing this also saves you the trouble of needing to delete the cookie.

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.