Reputation: 14625
To check what cookies exist i use this file (test.php):
foreach ($_COOKIE as $key => $value) {
print $key . "=" . $value . "</br>";
}
I get the following output:
fbsr_{app id}={a bunch of chars}
(Where the stuff within {} are private data)
To remove all my sessions i use this:
session_start();
session_unset();
session_destroy();
And this to remove my cookies:
setcookie('fbsr_' . $app_id, $_COOKIE['fbsr_' . $app_id], time() - 3600);
setcookie('PHPSESSID', $_COOKIE['PHPSESSID'], time() - 3600);
unset($_COOKIE['fbsr_' . $app_id]);
unset($_COOKIE['PHPSESSID']);
Problem is when i run the code to check if my cookies are dead, they are not, and i get the same output :/
Why are my cookies not removed? Is my code bad somewhere? tried several browsers...
EDIT: Seems like the cookies gets destroyed after all, but the test function still prints the cookie output?!?! im confused?!
(logout file)
if($action == 'logout'){
$app_id = $facebook->getAppID();
if (isset($_COOKIE['fbsr_' . $app_id])) {
echo 'goes here<br>';
setcookie('fbsr_' . $app_id, $_COOKIE['fbsr_' . $app_id], time() - 3600, "/");
setcookie('PHPSESSID', $_COOKIE['PHPSESSID'], time() - 3600, "/");
unset($_COOKIE['fbsr_' . $app_id]);
unset($_COOKIE['PHPSESSID']);
}
if (isset($_COOKIE['fbsr_' . $app_id])) {
echo 'is still sett<br>';
}
session_start();
session_unset();
session_destroy();
$result = array("success" => "true");
}
It never prints is still sett
which means the cookie is deleted!
Thank you :)
Upvotes: 1
Views: 1021
Reputation: 721
This is a method I have used to remove cookies
if (isset($_COOKIE['cookieName'])) {
setcookie('cookieName', '', time()-1);
}
Upvotes: 1