Maintaining Session Variables across Subdomains

前端 未结 2 1853
花落未央
花落未央 2021-02-06 14:24

I have been trying to maintain session vars between two subdomains and found it impossible. I ended up creating 2 minimal PHP web pages as a test bed, one I call \'test 1\' just

相关标签:
2条回答
  • 2021-02-06 15:03

    Ok I nailed it and it was a stinker.

    Suhosin's suhosin.session.cryptdocroot option was the entire cause of the problem. When the session encryption key is based on the DocRoot it causes the subdomains to fail to see each other's session variables when the base domain and the subdomains are served from different directories. This leads to the session vars on the server being stored in different folders and hence they are not visible to each of the corresponding domains.

    Solution. Simply add these 2 lines in your php.ini file:

    suhosin.session.cryptdocroot=Off
    suhosin.cookie.cryptdocroot=Off
    

    A 48 hour nightmare to track down, 4.8 seconds to fix.

    0 讨论(0)
  • 2021-02-06 15:26

    I have it working, setting a session name and session cookie parameters:

    $some_name = session_name("some_name");
    session_set_cookie_params(0, '/', '.some_domain.com');
    session_start();
    
    0 讨论(0)
提交回复
热议问题