Forum Moderators: coopster

Message Too Old, No Replies

Creating Cookies

Not working

         

Angelis

12:29 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



Hi just wondering if someone can give me the lowdown on Cookies and how to get them to work...

I have tried to following.

<?php
setcookie("prclicktrack", "id", time()+3600, "/","/", 0);
?>

It is not adding the cookie to my browser (or whatever) and doesnt appear in my cookies folder in my windows folder or from a page where I added

<?php
print_r($_COOKIE);
?>

Can anyone shed some light on how these work because I have been trying to get it to work for nearly 6 hours...

Any help appreciated...

Angelis

12:36 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



Just to clarify I dont need a session cookie, this cookie needs to sit on the visitors computer for a limited amount of time so that they can auto login each time they come back to the site etc etc.

dcrombie

1:13 pm on Oct 7, 2005 (gmt 0)



Why are you setting the "domain" to "/"? You would be better to leave it blank:

setcookie("prclicktrack", "id", time()+3600, "/");

or, if you want to share the cookie across the domain:

setcookie("prclicktrack", "id", time()+3600, "/", ".example.net");

;)

surfin2u

2:17 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



Here's code that I use to set a sitewide cookie that lasts a few years:

setcookie('v', $visit, time()+100000000, '/');

I wonder if setting the cookie is actually working for you and you don't realize it. You need to check for the cookie being set the next time you visit a page, not in the same page view that you set the cookie.