contra10 Posted March 11, 2009 Share Posted March 11, 2009 hi, my cookie is really causing me problems. when i set my cookie in the login page i try to make it available throughout th website <?php // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour, "/"); setcookie(Key_my_site, $_POST['pass'], $hour, "/"); header("Location: http://localhost/main/"); ?> it then directs to the main page. when i'm on other pages the cookie shows as it is suppose to but the problem is when i log out. my header file contains the logout button and this code <?php if (isset($_POST['logout'])) { $past = time() - 3900; //this makes the time in the past to destroy the cookie setcookie("ID_my_site", $username, $past); setcookie("Key_my_site", $pass, $past); // Create the URL string $url = "http://localhost/"; // Finall Echo the meta tag echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">'); } ?> when i try to log out from my main page it kills the cookie, however when i try to log out from any other page...profile, friends etc. i get redirected to the main page, of which if i then try to log out from that same main page it does so Quote Link to comment https://forums.phpfreaks.com/topic/148976-cookie-availability/ Share on other sites More sharing options...
premiso Posted March 11, 2009 Share Posted March 11, 2009 Should it be $_POST of logout or $_GET? Alternatively you can use $_REQUEST['logout'] and that checks for both and if that is set then the code runs. Since this is a logout page, I think that would be kosher. How do they logout from every other page? A button or a link with ?logout=true at the end? setcookie("ID_my_site", false); setcookie("Key_my_site", false); I would also use that for your logout cookies, as setting the value to false attempts to destroy to cookie. Quote Link to comment https://forums.phpfreaks.com/topic/148976-cookie-availability/#findComment-782238 Share on other sites More sharing options...
PFMaBiSmAd Posted March 11, 2009 Share Posted March 11, 2009 From the setcookie() page in the php manual - Cookies must be deleted with the same parameters as they were set with. If you are using the path parameter in the setcookie() statements to set the cookie, you must use the same parameters when you delete the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/148976-cookie-availability/#findComment-782240 Share on other sites More sharing options...
contra10 Posted March 11, 2009 Author Share Posted March 11, 2009 could i do something like this <?php if (isset($_POST['logout'])) { $past = time() - 3900; //this makes the time in the past to destroy the cookie setcookie("ID_my_site", $_COOKIE['ID_my_site'], $past, "/"); setcookie("Key_my_site", $_COOKIE['Key_my_site'], $past, "/"); // Create the URL string $url = "http://localhost/"; // Finall Echo the meta tag echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">'); } ?> ill try the request as well post is coming from button cause this is in the header file Quote Link to comment https://forums.phpfreaks.com/topic/148976-cookie-availability/#findComment-782250 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.