PHP authentication with multiple domains and subdomains

后端 未结 3 1822
有刺的猬
有刺的猬 2020-11-30 11:34

I have one main domain: main.com, subdomains: test1.main.com, test2.main.com and other domains one.com, two.com

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 12:04

    To keep your sessions going across multiple domains, you need to use session_set_cookie_params(). With that, you can specify your domain. For example...

    session_set_cookie_params(10000, "/", ".main.com");
    

    That will set the session timeout at 10,000 seconds for all documents under the site root, and for all subdomains of main.com.

    You should call session_set_cookie_params() before you do session_start().

提交回复
热议问题