How do I maintain PHP sessions across multiple domains on the same server?

后端 未结 2 1007
旧时难觅i
旧时难觅i 2020-12-18 01:58

I am looking for a way to maintain PHP sessions across multiple domains on the same server. I am going to be integrating my sites with a Simple Machines Forum so I will need

2条回答
  •  悲&欢浪女
    2020-12-18 02:09

    Depending upon your preferred method of modifying PHP variables (Apache's config, .htaccess), change the session.cookie_domain value to be a consistent value.

    I have multiple sub-domains, and each VirtualHost section in the Apache config file contains the following line:

    php_value session.cookie_domain mydomain.com

    The syntax should be similar if you make the changes in a .htaccess file.

    Updated for bobert5064's comment:

    For multiple domains (ie domain1.com, domain2.org), I think it is only necessary to choose a common domain name (ie domain1.com). I have never tried this, so I cannot verify that it works, but the logic seems accurate.

    There is also a method to set the variables direction in PHP described at http://us.php.net/manual/en/function.session-set-cookie-params.php. The documentation makes no reference to the ability or inability to set cookies on a different domain.

提交回复
热议问题