views:

164

answers:

2

I cant create a firefox cookie with following line:

    setcookie("TestCookie", $value, time()+3600, "/", "localhost");

does someone know why? i have checked the settings in FF and it accepts cookies from 3rd parties and are deleted when they expire.

EDIT: i can create now with this line:

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

but how do i delete it?

i tried with just switching the + to - but it didnt work.

$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()-60*60*24*365, '/', $domain, false);
A: 

Is "/" a valid path? Have you tried "/foo/"?

bobber205
valid path of? i dont quite understand what location path starts from.my webroot it in localhost/projects/blinder and the file calling it is index.php. what should the path and domain be set to?
never_had_a_name
+3  A: 

It's been awhile since I worked with localhost cookies, but according to the comments in the PHP manual, 'localhost' is an invalid value for the domain parameter.

To set a cookie on localhost, use false instead. Example:

setcookie("TestCookie", $value, time()+3600, "/", false);

See http://www.php.net/manual/en/function.setcookie.php#73107

zombat
thank you it worked. but now the problem is how do i delete it? see my updated version
never_had_a_name
To delete a cookie, you should set the expiration date to be in the past. In your case you'd use `setcookie("TestCookie", '', time()-3600, "/", false);`
zombat