sh0wtym3 Posted January 29, 2009 Share Posted January 29, 2009 My LOGIN.php has a line that sets the cookies, then redirects the user to MEMBERS.PHP: setcookie("mysite", $_POST['pass'], time()+3600); if(isset($_COOKIE['mysite'])) { header ("Location: members.php"); } And my LOGOUT.PHP page removes the cookies, then redirects the user to LOGIN.PHP: $past = time() - 3600; setcookie(mysite, gone, $past); header("Location: http://mysite.com/login.php"); ?> But LOGOUT.PHP won't delete the cookies, and the user keeps getting redirected back to MEMBERS.PHP when they try to log out. Why?? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 gone needs to be a 0 then the cookie is dead. or " " << cookie dead Quote Link to comment Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 Try setting the cookie parameters, domain and path. setcookie("mysite", $_POST['pass'], time()+3600, "/", ".yourdomain.com"); And to unset setcookie("mysite", "", $past, "/", ".yourdomain.com"); If you are trying to do this on localhost, let me know and I will post instructions on how to properly set/unset cookies on localhost, as it can be picky. Also it is a good idea to set the time 1 day back due to timezone issues. EDIT: If using localhost, you would use this to unset the cookies: To set the cookie: setcookie("mysite", $_POST['pass'], false, "/", false); To unset (sort of): setcookie("mysite", "", false, "/", false); I am not sure why that works with localhost (at least on Apache on Windows). That seems to work for me. Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted January 29, 2009 Share Posted January 29, 2009 gone needs to be a 0 then the cookie is dead. Makes no difference, cookies are deleted by their time, not their content. Your code: <?php $past = time() - 3600; setcookie(mysite, gone, $past); header("Location: http://mysite.com/login.php"); ?> Should be: <?php $past = time() - 3600; setcookie('mysite', gone, $past); header("Location: http://mysite.com/login.php"); ?> Missing quotes. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 corrected <?$past = time() - 3600; setcookie('mysite',' ', $past); header("Location: http://mysite.com/login.php"); ?> all you need is the domain name then the " " << empty then the $time variable. Quote Link to comment Share on other sites More sharing options...
sh0wtym3 Posted January 29, 2009 Author Share Posted January 29, 2009 I've tried every single suggestion in this thread but it still won't work The last one I tried was the localhost version you suggested premiso. My code is currently: LOGIN.PHP <?php // if login is ok then we start session setcookie("mysite", $_POST['pass'], false, "/", false); if(isset($_COOKIE['mysite'])) { header ("Location: members.php"); } ?> LOGOUT.PHP <?php $past = time() - 86400; //this makes the time in the past to destroy the cookie, set to 1 day before setcookie("mysite", "", false, "/", false); header("Location: login.php"); ?> I've used this same code on some php pages in my public_html folder and they work fine. However, this login.php and logout.php are located in a subdirectory within my public_html folder: public_html/members/ I don't know if this has anything to do with why it may not be working. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 try this please. <?php setcookie("mysite", "", time() - 3600, "/"); header("Location: http://mysite.com/login.php"); ?> or this <?php if(isset($_COOKIE['mysite'])){ setcookie("mysite", "", time() - 3600, "/"); header("Location: http://mysite.com/login.php"); exit; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.