Setting Cookies like a AM network

Status
Not open for further replies.

marcel

New member
Jun 26, 2006
246
2
0
www.landingpageforsale.com
I'm trying to set Cookies for 7 days or 1 month and 365 days on an entire domain. Like an AM network does.

This did not work

PHP:
       setcookie("final", $example, time()+(60*60*24*365));
it's only getting set on specific pages
I need it set on the entire domain.

I did look at the examples on http://www.php.net/setcookie
But it's not working. Maybe because I'm on localhost ? donno

Appreciated in advance
 


I think the better chance is your browser wont let you set a cookie for a year. Try lowering it - to like a week (change the 365 to 7), and see if it sets.
 
I think localhost might be the problem. Try using this code:

Code:
//if localhost, set to false, else to domain
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);

From the same page you link to, by the way: PHP: setcookie - Manual (<-- link to comment on page). Many issues are dealt with in the comments, I always read them first :)

I hope this helps.
 
That worked ! :)

rep++

Thanks



I think localhost might be the problem. Try using this code:

Code:
//if localhost, set to false, else to domain
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);
From the same page you link to, by the way: PHP: setcookie - Manual (<-- link to comment on page). Many issues are dealt with in the comments, I always read them first :)

I hope this helps.
 
Status
Not open for further replies.