[[LINK href="http://www.wpquestions.com/"]]We started with WP Questions[[/LINK]]. Now we've created this site, Symfony Experts. Although we've established 2 standalone sites, we are thinking that, moving forward, we will want to have a single over-arching domain for our sites. Then, potentially, our various sites could live as sub-domains of the larger site. For instance:
Next week I'm going to start working on the code for that future site. Ideally we could have a unified user system, and if you logged in once you could visit any sub-domain, but I'm not sure how to code that. Cookies do not carry from one sub-domain to another. Potentially I could hack something like url_for() so that the SESSION_ID is added to every URL? Has anyone written such a hacked version of url_for()? If so, could you please post the code?
And if the url_for() idea is a bad one, does anyone have a better suggestion?
Actually you CAN carry cookies between subdomains (and hence preserve sessions across related sites) by setting the domain name used in cookies to ".ourdomain.com" (note the leading dot which makes this a wildcard). In symfony that's set inside your application's factories.yml file.
Also, you dont need to hack session IDs in URLs (if you want that) - that's just another setting in symfony. I personally dont like session IDs in URLs, so my first answer is probably a better solution.
As Ajai said, you can share your cookies between subdomains by setting the domain name in your factories.yml file. Best, if you want to use several web servers to host your sites, you should store your sessions datas in a database. The setup is quite easy:
database: doctrine # the database name defined in your databases.yml file
And then create the session table (for mysql):
CREATE TABLE session (
sess_id char(32) not null primary key,
Actually, you'll need to add a dot in front of the desired domain name like so:
This information can be found right [[LINK href="http://www.symfony-project.org/reference/1_4/en/05-Factories#chapter_05_sub_session_set_cookie_params_parameters"]]here[[/LINK]].