Assigning and Passing Sessions Variables Between Subdomains

六月ゝ 毕业季﹏ 提交于 2019-12-07 08:35:43

问题


I am going to create a site that will have have multiple subdomains. For an example:

  • shop.domain.com
  • blog.domain.com
  • news.domain.com
  • account.domain.com

I would like to know if session variables can be passed between the subdomains. For an example $_SESSION['variable'] would be accessible on all of the subdomains listed above.


回答1:


You first have to make sure to store session data in a way that all hosts can access them; if they are hosted on the same machine everything is fine, otherwise you might want to use another session handler which e.g. uses a database, memcache, ... to store session data. Then you have to make sure the session id is available on all subdomains; this can be achieved by setting ini.session.cookie-domain.

For more information on sessions you should read the appropriate chapter in the fine php manual.



来源:https://stackoverflow.com/questions/6546999/assigning-and-passing-sessions-variables-between-subdomains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!