Forum Moderators: coopster

Message Too Old, No Replies

How to Make the cookie expire after a browser close

         

Gian04

3:57 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



I have set the cookies to expire after 24 hour, so after the user close his browser and if he revisit my site within 24 hours he is still logged.

How can I make it in such a way that if he close his browser and revisit my site (even after just a minute), he will be required to login?

Receptional Andy

3:59 pm on Jul 23, 2007 (gmt 0)



If you don't set an expiry date, the cookie will be a 'session cookie' so will be deleted when the browser session ends.

Gian04

4:09 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



Is this a correct syntax if I remove the expiration?

setcookie("Cookie_Name", $login_id, , "/", ".domain.com");

WesleyC

4:38 pm on Jul 23, 2007 (gmt 0)

10+ Year Member



No, this will throw a PHP error. Use 0 instead of the normal expiry time--this will set the cookie as a "session" cookie that will expire whenever the user closes his browser or leaves it inactive for a period of time--usually 20-30 minutes.

Receptional Andy

8:17 am on Jul 24, 2007 (gmt 0)



Remember that the PHP manual [php.net] usually answers such questions, in this instance with the documentation for setting a cookie [php.net]