Forum Moderators: coopster
eg.
server1 hosts www.mysite.com and www.yoursite.com
server2 hosts ww2.mysite.com and ww2.yoursite.com
I want both machines to accept cookies from both:
.mysite.com and .yoursite.com
So how do I set the php.ini
; The domain for which the cookie is valid.
session.cookie_domain = .mysite.com, .yoursite.com
?
or
session.cookie_domain = .mysite.com .yoursite.com
or is there a keyword that can be used to use the domain whichever site is being served
such as
session.cookie_domain = .$HTTP_REFFER['domain'].com
?
setcookie(Name,Value,Expire,Path,Domain) One for each domain.
From the manual [php.net]:
Re: Path
If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain.
I notice one other thing here and want to pose a question. You are referring to cookies (and SS has offered up the solution), but in your message you refer to sessions. At least the php.ini directive you are referring to is dealing with session cookies.
Sharing a session across servers is a bit more advanced. If the same subdomains reside on the same server, not as difficult. But if they are on different boxes, your strategy for sharing session information is going to be a bit more challenging.
Our need is to have two (and then more) load balanced webservers. Each webserver will serve pages for two different domains (that share a single code set). We have already databased the session data, but will need each webserver to have read/write access to a single PHPSESSID cookie for one or both of our domains. And since each webserver in the cluster will have a different subdomain, each server will need to be able to read/write that single cookie for each domain regardless of the subdomain that particular server has.
I'm pretty sure now that doing this in the php.ini session.cookie_domain is not possible.
So then my expectation is that we'll simply need to add check session cookie function as part of our custom session handler to look for an existing session cookie, and if one does not exist set it with the newly assigned session ID.
Does the latter solution sound right or do you know of any more built in session-related functionality to support this.
Thanks for the help! After doing a bunch of google searches and reading ALL the php.net docs I thought of WebmasterWorld as the best place to go =)
I'm wondering about the
session_set_cookie_params() function (more here [us2.php.net]. Maybe you could use that ...? I haven't used it before. From the docs, I can picture a cascade of individual function calls mangling the heck out of php.ini, but that may not be the case.
Just musing ... searching the PHP functions for session.cookie_domain turns up some possibilities.