Jump to content

Cookies will not delete/set


Lostnode

Recommended Posts

Ok, a bit of background.  I am working on a modified version of this script - http://www.evolt.org/node/60265

 

Now if I go by using the Log out script, it deletes the cookies no problem, here is the log out script

 

<?
session_start(); 
include("./inc/connect.php");
include("../global/login.php");

/**
* Delete cookies - the time must be in the past,
* so just negate what you added when creating the
* cookie.
*/
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
   setcookie("cookname", "", time()-60*60*24*100, "/");
   setcookie("cookpass", "", time()-60*60*24*100, "/");
}

if(!$logged_in){
   echo "<h1>Error!</h1>\n";
   echo "You are not currently logged in, logout failed. Back to <a href=\"index.php\">main</a>";
}
else{
   /* Kill session variables */
   unset($_SESSION['username']);
   unset($_SESSION['password']);
   $_SESSION = array(); // reset session array
   session_destroy();   // destroy session.

   echo "<h1>Logged Out</h1>\n";
   echo "You have successfully <b>logged out</b>. Back to <a href=\"index.php\">main</a>";
}
?>

 

Now the includes at the top of the log out page are already loaded from the index which pulls the following code when a form is filled out:

 

   
        
    $password = md5(stripslashes($_REQUEST['npass']));

    $update = "UPDATE users SET password = '$password' WHERE storeid = '$store' && username = '$username' "; $which = $handle_db1;
    $rsUpdate = mysql_query($update,$which);
    if ($rsUpdate) {
        echo "<h2>Password Update successful</h2>";
    }
    mysql_close();
    
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
     setcookie("cookname", "", time()-60*60*24*100, "/");
     setcookie("cookpass", "", time()-60*60*24*100, "/");
        }
   
   
    /* Kill session variables */
   unset($_SESSION['username']);
   unset($_SESSION['password']);
   $_SESSION = array(); // reset session array
   session_destroy();   // destroy session.
   echo "<Strong>Logged Out due to Password Change</strong><br>\n";
   echo "Please <a href=\"index.php\">login</a> with the new password";  

 

The parts are copied directly from the Log out page which is why I am trying to figure out why its not allowing me to remove the cookies cookname and cookpass.  I am at a lose, no errors come up, just the cookies still exist after I change the password and go to log back in.

 

The only differences I see are 1.  the if(!$logged_in) request is not in my moded code, and 2. neither is session_start() (which doesn;t matter cuz I did just try it to no avail)

I don't see any other issue with this.

 

 

Link to comment
https://forums.phpfreaks.com/topic/253811-cookies-will-not-deleteset/
Share on other sites

Do you have php's error reporting set up, and working?

 

As far as I know, I have been checking the error_log and see nothing in there that about this particular issue.  I have come up with a fix, which I am not happy about but it will have to do as it DOES work.  I moded the logout.php file so that the removal of the cookies falls under the !logged_in() part and it seems to work fine, but i really would like them to be logged out before clicking the link to log back in.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.