note 56887 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Sun, 18 Sep 2005 18:14:20 +0000 |
| Subject: | note 56887 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95372@lists.php.net to get a copy of this message | ||
Note Submitter: jesper at angelo dot net
Reason: useless
----
I recently had to get the level 2 domain name for a login application, so I can set cookies for the
domain itself and not just whichever subdomain people use. ie. turning this:
www.6dots.net:80
into this:
.6dots.net
This will do the trick:
$pattern="/^(\w+\.)(\w+\.\w+)(:.*$)*/";
$replace=".$2";
$cookiedomain = preg_replace($pattern,$replace,$_SERVER["HTTP_HOST"]);
print("COOKIE DOMAIN: ".$_SERVER["HTTP_HOST"]." -->
".$cookiedomain);