PHP Cookie question!

Forum: ProgrammersTotal Replies: 4
Author Content
J_Maxwell

Aug 25, 2004
4:53 PM
Hello,

I am trying to create a logout function in my cart. I checked back at other posts to see how this is done, but it doesn't seem to work. Here's how I am attempting to do it:

header("Set-Cookie:user=null;");
setcookie("user", "null");

However, it doesn't clear or erase the cookie! Ideas?

Thanks for your help,

Joseph
dave

Aug 26, 2004
10:39 AM
The key is, you have to clear the cookie the same way you set it.

I set the cookie like this:

header("Set-Cookie:password=PASS;expires=Friday, 16-Jan-2037 00:00:00 GMT");

Then I clear the cookie like this:

header("Set-Cookie:password=;expires=Friday, 16-Jan-2037 00:00:00 GMT");

Notice it is identical, except for the value of password. That works for me.

dave
J_Maxwell

Aug 26, 2004
11:59 AM
Thanks! I don't know what was going wrong before -- that fixed it.

Thanks for your help,

Joseph
dave

Aug 26, 2004
1:08 PM
Happy to help!
James

Oct 03, 2006
1:01 PM
You could also set the expiration date to a value in the past. Then the browser would immediately expire the cookie and delete it. You could either use the header() function, or use setcookie() to do the same thing, just with an easier syntax. You would use:

setcookie("password", "", time() - 3600); // Set the expiration date to an hour ago.

Besides clearing the password, it would also delete the cookie from the user's browser.

James

Posting in this forum is limited to members of the group: SITEADMINS, SUBSCRIBERS, MEMBERS.]

the Open Forums!

  Login
If you don't have an account yet, visit the registration page to sign up.

If you already have an account, you may login here:

Username: Password:

  Welcome to the Open Forums!!
Welcome to the Open Forums!!

  Hosted By...

This website is hosted by:

 -
PreparingSons
 - Titus2.com


[ Copyright © the Open Forums! | All times are recorded in ET ]

[ Contact Us ]

Login

Powered by Scif 5.3 build 285 by StandardOut, Inc.