making cookies last longer than 1 session.

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
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

making cookies last longer than 1 session.

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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]]]]])
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

thank you feyd :-D

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

yay1
LostMyLove
Forum Newbie
Posts: 20
Joined: Mon Sep 27, 2004 12:20 pm

Post 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 ?
Breckenridge
Forum Commoner
Posts: 62
Joined: Thu Sep 09, 2004 11:10 pm
Location: Breckenridge, Colorado

Post by Breckenridge »

Domain value is optional
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Breckenridge
Forum Commoner
Posts: 62
Joined: Thu Sep 09, 2004 11:10 pm
Location: Breckenridge, Colorado

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 :)
Post Reply