Page 1 of 1

Another quick cookie technicality question

Posted: Fri Dec 12, 2003 11:19 am
by kirilisa
If the expire parameter in setcookie() is set to 0, that means that the cookie will remain around as long as the browser is open.

What I wonder is, does browser closed mean that that particular browser window is closed, or the whole browser application is closed?

I have a script that sets a cookie, and when you have that cookie, you are allowed to view secretpageA.php. secretpageA.php has code in the beginning testing whether or not you have that particular cookie. I noticed that when I had successfully authorized and gooten my cookie and gone to secretpageA.php, if I opened a new browser window (keeping originally, authenticated page open) and went also to secretpageA.php, it told me I wasn't authorized and didn't have the cookie.

Is this how it is supposed to work or not?

Posted: Fri Dec 12, 2003 11:34 am
by aquila125
Not very secure is it? I place a selfmade cookie in my cookies folder and I get access to your secretpage..

thanks! :-)

Posted: Fri Dec 12, 2003 11:51 am
by kirilisa
:( Blah, that was the first cookie I ever made. I'm still trying to figure it out. If you have pointers, please share!

Anyway, that didn't answer my question :?

Posted: Fri Dec 12, 2003 2:09 pm
by DuFF
From PHP.net:
time()+60*60*24*30 will set the cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes).
So just use

Code: Select all

<?php
setcookie ("TestCookie", $value);
?>
Or you can use sessions which will accomplish the same thing.