note 70442 deleted from function.setcookie by bjori
| From: | bjori@php.net | Date: | Mon, 08 Jan 2007 10:53:04 +0000 |
| Subject: | note 70442 deleted from function.setcookie by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121441@lists.php.net to get a copy of this message | ||
Note Submitter: geoff at spacevs dot n0spm dot com
----
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.