Another quick cookie technicality question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirilisa
Forum Commoner
Posts: 28
Joined: Fri Dec 05, 2003 4:41 pm

Another quick cookie technicality question

Post 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?
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

Not very secure is it? I place a selfmade cookie in my cookies folder and I get access to your secretpage..

thanks! :-)
kirilisa
Forum Commoner
Posts: 28
Joined: Fri Dec 05, 2003 4:41 pm

Post 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 :?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Post Reply