I'm trying to get a cookie to delete after it's used in my code, and I can't get it to delete for the life of me. So I pulled the add/delete code out into a separate file, to see if it was something I did wrong, and if I could fix it outside of my script and get it to work, I could add it back in.
Alas, no luck, so I'm here to see if one of you geniuses could lend a hand
Here's the code:
<?php
/**
* @desc Sets the joinfree cookie
* @param string $value The content you want stored in the cookie. Set to '' to delete the cookie
*/
function set_join_cookie($value) {
$domain = '.mydomain.com';
$path = '/';
return setcookie("joinfree1", $value, time()+604800);//, $path, $domain);
}
/**
* @desc Deletes the joinfree cookie
*/
function delete_joinfree_cookie() {
$domain = '.mydomain.com';
$path = '/';
unset($_COOKIE['joinfree1']);
return setcookie("joinfree1", false, time() - 31536000);//, $path, $domain);
}
//echo 'Add: ' . set_join_cookie('http://mydomain.com/joinfree');
echo 'Delete: ' . delete_joinfree_cookie();
?>
I switched the commented line at the bottom between Add/Delete for the test. It added the cookie with no problem, but I could never get it to delete. Also, is the unset command required? I added it when I saw that as a suggestion, but see no need for it, since the $_COOKIE array never gets sent back to the browser, does it?
Thanks for your help!