Page 1 of 1

making cookies last longer than 1 session.

Posted: Thu Sep 30, 2004 4:04 pm
by Daisy Cutter
I'm trying to get my site to warn IE users about their browser's incompliance, but I also want to let them set a cookie to get rid of the warning if they don't want it.

Right now I have

Code: Select all

<?php
setcookie("dontbugmeaboutie", time()+3600000);
header("Location: /");
exit;
?>
but I want this to last for the whole ~40 days. It currently only lasts for the session, then dies when I reopen internet explorer. In preferences cookies are set to last.

Posted: Thu Sep 30, 2004 4:08 pm
by feyd
you have the wrong argument order:
[php_man]setcookie[/php_man] wrote:bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]])

Posted: Thu Sep 30, 2004 5:18 pm
by Daisy Cutter
thank you feyd :-D

i had to make it setcookie("dontbugmeaboutie", "dontbugmeaboutie", time()+3600000)

yay1

Posted: Thu Sep 30, 2004 7:03 pm
by LostMyLove
i had a question:

bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]])

the domain is what?

i can do it without a value or need a value ?

Posted: Thu Sep 30, 2004 7:07 pm
by Breckenridge
Domain value is optional

Posted: Thu Sep 30, 2004 8:14 pm
by feyd
if you set the cookie in subdomain x, and want to access it in subdomain y, then you have to set the domain value, either in the cookie call, or with any of the ini setting functions.

Posted: Fri Oct 01, 2004 10:38 pm
by Breckenridge
I have only used linux / Mozilla based browsers for the past 3 years. I always thought that the browser will give a warning if a cookie is being accessed by a different domain. Does that apply to subdomains?

Posted: Sat Oct 02, 2004 12:13 am
by feyd
when (the browser is) working properly, the cookie isn't visible to any site but the domain it was set on. Additionally, a domain cannot set a different domain. Subdomains can set a cookie against the parent domain, because they are the same (to the browser). However, if a subdomain is set as the domain setting, then only that subdomain can access the cookie; although I'm not sure about the parent domain being able to access a subdomain cookie, as I haven't worked with that as yet :)