[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Cookies in memory only?

Is it possible to set cookies in a browsers memory only with PHP's setcookie, or otherwise? I know coldfusion lets you set a timed lifespan for cookies, or lets you specify that they become void when the browser is closed.

I need to do this in PHP for a member ship system I am writing.
1 Solution
Yes that is possible.

You can specify the time parameter in PHP's setcookie function. If you set that parameter to 0 the cookie is deleted when the browser is closed.

- chkassen
Actually, a time of 0 sets the cookie to never expire.

Set a cookie's time using the time() function and the number of minutes you want it to be active times sixty. eg the time string for five minutes would be :

$time = time() + 360;

brettfosterAuthor Commented:
Actually I just tried it setting the time value to 0, and it worked great in Netscape. I don't know if this is different in IE, but I'd hope/expect not.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now