note 10516 added to setcookie
| From: | tmiller at creativegeneration dot com | Date: | Mon, 08 Jan 2001 22:08:47 +0000 |
| Subject: | note 10516 added to setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9484@lists.php.net to get a copy of this message | ||
If you're having problems setting cookies on a sub-domain but you don't want to hard code
it you can do something like this:
$dom = $HTTP_HOST;
if (preg_match("/^(.*):(.*)$/",$dom,$arr)) {
$dom = $arr[1];
}
$parts = explode(".",$dom);
$dom = ".".$parts[count($parts)-2].".".$parts[count($parts)-1];
setcookie("cookiename","cookievalue","/",$dom);
Now you will be able to move the site from dev.yourdomain.com to www.yourdomain.com without hard
coding the domain name.
-Toby
http://www.php.net/manual/function.setcookie.php