deleting cookies

Right now, i’m rather po’d with this logout script. It was working, and now its not. All i’ve done is add 2 more cookies. I’ve read through countless posts on destroying cookies. most say to just set the time to something in the past, but its not working anymore. I’ve been at this for several hours now, i’m tired and not all that happy right now since i can’t test another script change i was working on for another project.

anyways, this is what i have currently:
[php]if($_GET[‘do’] == “logout”) {

$_SESSION = array();
$_COOKIE = array();

if (ini_get("session.use_cookies")) {
	$params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
    $params["path"], $params["domain"],
    $params["secure"], $params["httponly"]);
}

session_destroy();

foreach($_COOKIE AS $val) {
	setcookie($val,'', time()-60*60*24*30, '/', '.venzodigital.com');
}

header("Location: index.php");

}[/php]
The sessions are being destroyed but reset again because the cookes aren’t being erased like they should be.

this is my original logout file
[php]session_destroy();
setcookie(“user”,"",mktime(12,0,0,1, 1, 1990), “/”, “.venzodigital.com”);
setcookie(“pass”,"",mktime(12,0,0,1, 1, 1990), “/”, “.venzodigital.com”);
setcookie(“id”,"",mktime(12,0,0,1, 1, 1990), “/”, “.venzodigital.com”);
// these 2 are what was added
setcookie(‘itunes’,"",mktime(12,0,0,1, 1, 1990), ‘/’, ‘.venzodigital.com’);
setcookie(‘apps’,"",mktime(12,0,0,1, 1, 1990), ‘/’, ‘.venzodigital.com’);
header(“Location: index.php”);[/php]

So now its not working and i have no clue as to why. Could use some help here!

Not sure, but, I have been told to delete cookies, like this:
unset($_COOKIE[‘cookie-name’]);

Cookie-name can be a variable without the quotes of course…

Also, usually, I remove cookies before I close the session. Not sure if that really matters!

And, for testing, you can use print_r($_COOKIE);
to see what you have in your cookies array. (To verify they are closed…)

Hope that helps… Good luck…

Well i don’t know quite what the problem was. but i went back the original setcookies. Odd thing is that it breaks if i remove that $_SESSION = array();

Well, you can’t set the $_SESSION variable as an array because it already IS an array.
When you create a session variable it is like this: $_SESSION[‘variablename’]; SO, this IS an array!

So, you can’t set it to another array… But, glad you got it working…

I pulled it from a website, i was trying everything under the sun to get it to work. The sessions were being removed, but then just getting reset again because of how i have the login script and cookies setup. It was the cookies that were giving me the heart attack :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service