note 22039 deleted from function.setcookie by philip

From: Date: Tue, 16 Jul 2002 16:56:26 +0000
Subject: note 22039 deleted from function.setcookie by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-33149@lists.php.net to get a copy of this message
Ok..I had multiple scripts that handled a login system, the scripts that were important (and relate to cookies) were my login/logout scripts (both seperated) Next, after I had everything working, I was able to log in (by setting a cookie) and log out(by deleting the cookie) the code i used: (set cookie in user-login.php) setcookie ("cookie_encrypt_pw", $cookie_encrypt_pw, time()+3600); setcookie ("cookie_user", $cookie_user, time()+3600); (unset cookie in user-logout.php) setcookie ("cookie_encrypt_pw", "", time()-360000); setcookie ("cookie_user", "", time()-360000); this worked fine!! ...until... i tried to combine the two scripts into one so i had user-login&step=2 for login and step=3 for logout...my script no longer would log me out (but i could still log in fine) I was then reading this documentation, and i must have misunderstood...because 2 people have said something about using setcookie in the script more then once. at first i wasnt sure, but now i am almost positive that the setcookie() will always be run!!! here is a small example (similar to what someone already had) if($xx=1){ setcookie("cookie1","data"); } if($xx=2){ setcookie("cookie2","data"); } i am pretty sure (have not yet tested this actual exampole) ...but if $xx=1 or $xx=2 it probably wont matter, and both cookie1 and cookie2 will be set. Either that, or neither will be set...i have yet to check that....hope this makes sense/helps ...however, this still makes me wonder why i was able to login without being logged out right after...

« previous php.notes (#33149) next »