TapeGun007 Posted July 7, 2010 Share Posted July 7, 2010 Ok, I'm just about at my wits end here. I cannot seem to remove cookies... period. I've tried everything, including Javascript in an attempt to get this to work. When programming in ASP, it was so simple and worked everytime, I would just code: Response.Cookies("FirstName").Expires = Date () -1 And it was done, no worries, no issues, no hassles. That cookie would be done with. In php however, I cannot get anything to work. Even closing the browser and reopening it does NOT get rid of the cookie. I've tried this in MSIE 8, Firefox, AND Chrome. I get the same result in each browser. I've even deleted all cookies on my system. As a matter of fact, I deleted everything that IE would allow me to delete to test. I've experimented with several things this code is in the login page.: If ($_GET["logout"]=="yes") { setcookie("Active","",mktime(12,0,0,1, 1, 1990),"". ""); setcookie("MemberID","",mktime(12,0,0,1, 1, 1990), "", ""); setcookie("FirstName","",time()-186400, "", ""); setcookie("LastName","",time()-186400, "", ""); header('Location:login.php'); exit; } At the bottom of the login.php page, I have this: echo $_COOKIE['Active']."<br>"; echo $_COOKIE['MemberID']."<br>"; echo $_COOKIE['FirstName']."<br>"; echo $_COOKIE['LastName']."<br>"; Ok, so assume that I have completely wiped my computer of all cookies and internet junk. I login to the page, the cookies are obviously setting correctly, so that's not an issue. $_COOKIE['Active'] always is set to "yes", and every other cookie is wiped out the FIRST time I log in and log off. If I log in and log out a 2nd time, all the cookies are intact and none of them are deleted. Can someone please explain what in the world I am doing wrong here? I'm extremely frustrated and coming here as a very last resort after exhausting myself on this subject! If you need something else from my code, let me know... I'll be glad to provide it. Quote Link to comment https://forums.phpfreaks.com/topic/206953-i-cant-remove-cookies-in-php-for-some-reason/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2010 Share Posted July 7, 2010 A) You didn't show us how you are setting the cookies, because they must be deleted using matching parameters. B) The $_COOKIE variables are set by the browser and so would only show the updated values after a page has been requested. C) Its' not clear from your description, but you likely have a logic error that is setting the cookies, perhaps due to the code following a header() redirect that does not have an exit(); statement after it to prevent the remainder of the code on the page from being executed. Quote Link to comment https://forums.phpfreaks.com/topic/206953-i-cant-remove-cookies-in-php-for-some-reason/#findComment-1082216 Share on other sites More sharing options...
TapeGun007 Posted July 7, 2010 Author Share Posted July 7, 2010 Ok, then I edited all the things I don't want people to see out, but this is really the main code for my login.php page. <?php /* Delete all associated cookies */ If ($_GET["logout"]=="yes") { setcookie("Active","",mktime(12,0,0,1, 1, 1990),"". ".sanjosechoir.com"); setcookie("MemberID","",mktime(12,0,0,1, 1, 1990), "", ".sanjosechoir.com"); setcookie("FirstName","",time()-186400, "", ".sanjosechoir.com"); setcookie("LastName","",time()-186400, "", ".sanjosechoir.com"); header('Location:login.php'); exit; } ?> <?php include("components/dbconnection.php"); /* Just check to see if the email field on the form is set */ if (isset($_POST["User_Email"])){ $UserEmail = $_POST["User_Email"]; $Password = $_POST["User_Password"]; $result = mysql_query("SELECT * FROM Members WHERE Email='$UserEmail' AND Pword='$Password'"); while($row = @mysql_fetch_array($result)) { if ($row['Active']=="yes") { /* Set the User_ID for later use to check and see if they are in leadership */ $UserID=$row['MemberID']; /* Set cookies to identify the user without accessing the database again */ setcookie("MemberID",$row['MemberID'],time()+3600*24); setcookie("Active",$row['Active'],time()+3600*24); setcookie("FirstName",$row['FirstName'],time()+3600*24); setcookie("LastName",$row['LastName'],time()+3600*24); $Active = "true"; } Else { $Error="<span class='error'>Your login is correct, however, your account is currently not activated. Please contact an administrator.</span>"; } } if ($Active=="true"){ $date = date("m/d/Y"); $MemberID = $_COOKIE['MemberID']; $result = mysql_query("UPDATE Members SET Last_Login='$date' WHERE MemberID='$MemberID'"); mysql_query($result); header('Location:index.php');; exit; } // $Error="<span class='error'>Invalid Username and/or Password</span>"; mysql_close($con); } ?> <?php include("components/header.php"); ?> <span class="ContentBold">Login:</span> <p> <form action="login.php" method="post"> <table border="2" bordercolor="#333333"><tr><td> <table cellpadding="2" cellspacing="0"> <tr> <td><b>Email:</b></td><td><input name="User_Email" value="<?php if (isset($_COOKIE['UserEmail'])) echo $_COOKIE['UserEmail'] ?>" class="input" /></td> </tr> <tr> <td><b>Password:</b></td><td><input name="User_Password" type="password" value="<?php if (isset($_COOKIE['UserPass'])) echo $_COOKIE['UserPass'] ?>" class="input" /></td> </tr> <tr><td colspan="2" align="center"><input src="images/btn_Submit.gif" type="image" align="middle" /> </td></tr> </table> </td></tr></table> </form> <?php if (isset($Error)) echo '<br>'.$Error."<p>"; ?><p> <p><p> Cookies that are still set:<p> <?php echo $_COOKIE['Active']."<br>"; echo $_COOKIE['MemberID']."<br>"; echo $_COOKIE['FirstName']."<br>"; echo $_COOKIE['LastName']."<br>"; ?> <?php include("components/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/206953-i-cant-remove-cookies-in-php-for-some-reason/#findComment-1082218 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.