/    Sign up×
Community /Pin to ProfileBookmark

Deleat the cookie

I set a cookie called YourLocalCookie. I not sure how to delete it. Here is the cookie that I set

setcookie (“YourLocalCookie”,$cookie_data,time()+60*60*24*90);

This is what I’ve been trying to do to delete the cookie.

if (isset($_COOKIE[‘YourLocalCookie’])) {
$time = time();
setcookie (“YourLocalCookie”,””, $time – 3600);
}

What should I do?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 07.2004 — Afraid I don't know much about cookies, but the fact that you want to delete it sort of says to me that maybe you should be using [url=http://us2.php.net/manual/en/ref.session.php]PHP session functions[/url] instead, perhaps?
Copy linkTweet thisAlerts:
@96turnerriDec 07.2004 — 60*60*24*90 != 3600

60*
60*24*90 == 7776000

thus making

setcookie("YourLocalCookie","", $time-7776000);

[i]Originally posted by NogDog [/i]

[B]but the fact that you want to delete it sort of says to me that maybe you should be using [url=http://us2.php.net/manual/en/ref.session.php]PHP session functions[/url] instead, perhaps? [/B][/QUOTE]


what about a logout feature, that would require the deletion of cookies ?
Copy linkTweet thisAlerts:
@NogDogDec 07.2004 — [i]Originally posted by 96turnerri [/i]

[B]what about a logout feature, that would require the deletion of cookies ? [/B][/QUOTE]

To be thorough, yes, but for the stuff I've done with sessions, just unsetting the _SESSION vars and doing a session_destroy() seemed to work fine. (Mind you, these were not security-sensitive applications.)

The php.net documentation suggests:
[code=php]
<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();
?>
[/code]


As to the original question, I just noted that in the documentation it says:
Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. [/quote]
This would appear to mean that if you used any of the optional args after the expiration time when setting the cookie, you must include them again when deleting it?
Copy linkTweet thisAlerts:
@96turnerriDec 07.2004 — [i]Originally posted by NogDog [/i]

This would appear to mean that if you used any of the optional args after the expiration time when setting the cookie, you must include them again when deleting it? [/B][/QUOTE]


as my code does ?
×

Success!

Help @madddidley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...