SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Sean N Pixel Inception's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions across domains and subdomains.

    Hey guys I had a question about sessions across a subdomain and main domain. I used to know how to do this but im having a brain fart right now. Right now I have a session that is created at sub.mydomain.com. I need to access the session at mydomain.com aswell. Does anyone know a solution?
    Sean @ Pixel Inception, Inc. www.pixelinception.net
    Web Design & Web Development

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    London, United Kingdom
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can change the session cookie domain for the scripts at sub.mydomain.com using
    http://php.net/manual/en/function.se...kie-params.php
    Then you will have one session for both domains.

    If you cannot do this, you can implement your write and install your custom session handler using session_set_save_handler. For example, you can save it session data to database and read it with custom queries.
    CodeReview4U - boost your code and skills for
    being social - JavsScript and C# code reviews.

  3. #3
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlexVN View Post
    If you cannot do this, you can implement your write and install your custom session handler using session_set_save_handler. For example, you can save it session data to database and read it with custom queries.
    And that solves the cookie problem in which way?

    If you'd like to use session cookies within the complete domain just set the cookie domain to ".example.com" - the dot before the domain name is required.
    Cross-domain (e.g. example.com and example.net) isn't possible, use something like OpenID for this.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    London, United Kingdom
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >And that solves the cookie problem in which way?
    I suppose that Sean may want to access the data of the session in another domain, not just merge them.
    CodeReview4U - boost your code and skills for
    being social - JavsScript and C# code reviews.

  5. #5
    Sean N Pixel Inception's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys, thanks for the replies. I just want to access the session that was created on my subdomain on my main domain. I'll look into the function you have posted.
    Sean @ Pixel Inception, Inc. www.pixelinception.net
    Web Design & Web Development

  6. #6
    Sean N Pixel Inception's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok guys, I remember how I did this.

    For people who would like to know,

    ini_set("session.cookie_domain", ".mysuperflydomain.com");

    before every session_start(); on both subdomain session_starts as well as the main domain session_starts.
    Sean @ Pixel Inception, Inc. www.pixelinception.net
    Web Design & Web Development


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •