setcookie not working...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

setcookie not working...

Post by Meteo »

I had some weird trouble with the setcookie function, still do actually...

i have some scripts, on the main script it always checks for a cookie to see if someone's logged in and checks that cookie info with the database, if it disagrees with database info, then i just do setcookie($cookie); and it works, it unsets the cookie.

but for some reason it wont here...

Code: Select all

if ($_COOKIE[$cookie]) {
      setcookie($cookie);
      header("Location: place.php");
} else {
      // no cookie's set, show login forms...
}
it passes the test, but doesn't unset the cookie. it's just headers back to place.php still having the cookie set...

any ideas of what could be going on here? the exact same line works on the other script, but not this one. :x :?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I just do this to unset cookies

Code: Select all

<?php
unset($_COOKIE[$cookie]);
?>
User avatar
Meteo
Forum Newbie
Posts: 24
Joined: Sun Jan 18, 2004 10:19 am
Contact:

Post by Meteo »

i dont know, for some reason it just wont delete the cookie.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

to delete a cookie:

the value argument must be an empty string. The expiry time, must be in the past, generally by several days to make sure. The path and domain and security must match the original cookie sent.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

an example can be found at php.net, search for setcookie

if an example is needed to what feyd was talking about
Post Reply