note 10516 deleted from function.setcookie by john

From: Date: Sat, 30 Nov 2002 16:14:23 +0000
Subject: note 10516 deleted from function.setcookie by john
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-40153@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

« previous php.notes (#40153) next »