never_had_a_name
never_had_a_name

Reputation: 93176

why can't I create cookies in Firefox?

I am not able to 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 didn't work.

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

Upvotes: 1

Views: 6879

Answers (1)

zombat
zombat

Reputation: 94157

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

Upvotes: 4

Related Questions