How to pass SESSION variable to a page in the parent directory?

前端 未结 2 517
旧巷少年郎
旧巷少年郎 2021-01-07 14:30

On my web site I would like to have several sub-domains. Files that create context for a given sub-domain are stored in corresponding sub-directory.

Sometimes I nee

相关标签:
2条回答
  • 2021-01-07 14:30

    In PHP INI you can set the session domain to ".mysite.org" then you should be able to share the session between multiple domains. The relevant variable is:

    session.cookie_domain

    You can also set it inside your script with the session_set_cookie_params() function.

    Edit - I should note this only works if your subdomains are on the same server (which looks like they are).

    0 讨论(0)
  • 2021-01-07 14:53

    You're right that sessions cannot be shared in this way. However, you can use secure cookies to share user data across subdomains:

    http://us3.php.net/manual/en/function.setcookie.php

    Make sure the domain parameter when you set the cookie is something like

    ".mysite.org"
    

    Then you'll be able to access the cookie from any subdomain of mysite.org

    0 讨论(0)
提交回复
热议问题