note 70442 added to function.setcookie

From: Date: Tue, 17 Oct 2006 01:55:23 +0000
Subject: note 70442 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-118594@lists.php.net to get a copy of this message
I had two sites for the same domain under different names that I wanted the cookie to be maintained between: forum.* www.* Because forum is running a phpbb2 forum, I did not want to modify the forum code to set the domain in the cookie, so to override the default behaviour of using the entire domain name, I wrote the following code and pre-pended it to the output using the php_auto_prepend setting. <?PHP $domain = 'example.com'; function fix_cookies($data) { global $domain; foreach(headers_list() as $value) { list($name, $value) = split(': ', $value, 2); if ($name == 'Set-Cookie') header("$name: $value; domain=.$domain"); } return $data; } ob_start('fix_cookies'); ?> Now the domain for all cookies is set to .example.com and will now work across subdomains. If there is a better way, please let me know. ---- Server IP: 203.16.234.19 Probable Submitter: 165.12.252.12 (proxied: unknown) ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/70442 Del: integrated -- https://master.php.net/note/delete/70442/integrated Del: useless -- https://master.php.net/note/delete/70442/useless Del: bad code -- https://master.php.net/note/delete/70442/bad+code Del: spam -- https://master.php.net/note/delete/70442/spam Del: non-english -- https://master.php.net/note/delete/70442/non-english Del: in docs -- https://master.php.net/note/delete/70442/in+docs Del: other reasons-- https://master.php.net/note/delete/70442 Reject -- https://master.php.net/note/reject/70442 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118594) next »