Forum Moderators: coopster

Message Too Old, No Replies

Making Members Area with setcookie

         

omak

4:18 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



Hi all,

I'm writing a members login area with php and MySQL. I'm using setcookie to store my "logined" status after the username and password are verified. But I'm just wondering how to I write the logoff part?

Using session, I could just simply use session_destroy() to log off the user. But how do I do that in cookie?

CyBerAliEn

4:43 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



I predominantly use sessions instead of cookies now, so I cannot give you the exact code to use...

But when you set the cookie, you gave it an expiration time (some time into the future), correct?

When the user logs out, to "destroy" the cookie... use PHP to alter/modify the cookie with a negative/old/past expiration.

With an "old" expiration, the browser will clear/delete the cookie, "logging off" your user.

optik

5:06 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



you set the expiration time to a date in the past

rocknbil

9:29 pm on Dec 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^ ^ This is correct, for both session cookies and persistent cookies. Session cookies have no expiration date and die when the browser is closed. In this age, that can be weeks on end. :-)

Persistent cookies are set and updated with a specific expiration date in GMT format. These cookies will NOT go away when the browser is closed, but will only die when that expiration date has passed.

As mentioned, you can kill both by setting an expiration date in the past, but to work it has to be a valid format. An invalid date won't set properly.