logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$20
How to carry session info from sub-domain to sub-domain

We started with WP Questions. 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:

mysql.ourDomain.com

groovy.ourDomain.com

rubyonrails.ourDomain.com

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?

This question has been answered.

Lawrence Krubner | 02/19/10 at 5:21pm Edit


(4) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/21/10
    11:42am
    Ajai Khattri says:

    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.

  • avatar
    Last edited:
    02/21/10
    11:42am
    Noel GUILBERT says:

    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:


    # apps/YOUR_APP/config/factories.yml
    storage:
    class: sfPdoSessionStorage
    param:
    session_cookie_domain: .domain.com
    database: doctrine # the database name defined in your databases.yml file
    db_table: session


    And then create the session table (for mysql):

    CREATE TABLE session (
    sess_id char(32) not null primary key,
    sess_data LONGTEXT,
    sess_time INTEGER
    );

    Previous versions of this answer: 02/21/10 at 8:36am

  • avatar
    Last edited:
    02/21/10
    7:13am
    Daniel Lohse says:

    Actually, you'll need to add a dot in front of the desired domain name like so:


    # apps/YOUR_APP/config/factories.yml
    storage:
    class: sfPdoSessionStorage
    param:
    session_cookie_domain: '.symfonyexperts.com'


    This information can be found right here.

  • avatar
    Last edited:
    02/21/10
    2:31am
    Ajai Khattri says:

    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.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.