PHP Sessions across sub domains

前端 未结 17 1667
慢半拍i
慢半拍i 2020-11-22 05:59

I am trying to set up the following:

auth.example.com
sub1.example.com
sub2.example.com

If the user visits sub1.example.com or

17条回答
  •  温柔的废话
    2020-11-22 06:15

    I have read all answers above, I think my answer is helpful for people googling this:

    • make sure the browsers send session cookie back to servers (of domain and sub-domains), set session cookie domain as .example.com.

    • Make sure PHP find the right "target" to restore the session variable:

      • If domain and subdomains point to the same machine (maybe different virtual hosts), make sure session_save_path is the same for all (I tested)
      • If domain and subdomains point to different machines, the common storage (like database) is best for saving and restoring session data (I didn't test yet). Use session_set_save_handler to do that.

提交回复
热议问题