note 73107 added to function.setcookie
| From: | php-general at lists dot php dot net | Date: | Fri, 09 Feb 2007 01:13:01 +0000 |
| Subject: | note 73107 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123161@lists.php.net to get a copy of this message | ||
something that wasn't made clear to me here and totally confused me for a while was that domain
names must contain at least two dots (.), hence 'localhost' is invalid and the browser
will refuse to set the cookie! instead for localhost you should use false.
to make your code work on both localhost and a proper domain, you can do this:
<?php
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ?
$_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain,
false);
?>
----
Server IP: 216.194.113.175
Probable Submitter: 172.207.22.131
----
Manual Page -- http://www.php.net/manual/en/function.setcookie.php
Edit -- https://master.php.net/note/edit/73107
Del: integrated -- https://master.php.net/note/delete/73107/integrated
Del: useless -- https://master.php.net/note/delete/73107/useless
Del: bad code -- https://master.php.net/note/delete/73107/bad+code
Del: spam -- https://master.php.net/note/delete/73107/spam
Del: non-english -- https://master.php.net/note/delete/73107/non-english
Del: in docs -- https://master.php.net/note/delete/73107/in+docs
Del: other reasons-- https://master.php.net/note/delete/73107
Reject -- https://master.php.net/note/reject/73107
Search -- https://master.php.net/manage/user-notes.php