简体   繁体   English

php子域会话共享

[英]php subdomain session sharing

I need to share a session between two subdomains. 我需要在两个子域之间共享一个会话。

I have these domains: 我有这些域:

http://example.com http://example.com
https://secure.example.com https://secure.example.com

And I tried session sharing with this way: 我尝试通过这种方式进行会话共享:

<?php ini_set("session.cookie_domain", ".example.com"); session_start(); ?>

And this also 这也

<?php session_set_cookie_params ( 0,"/" ,".example.com"); session_start(); ?>

But both seems not working! 但是两者似乎都不起作用!

How can I make it works? 我该如何运作?

Sorry for bad English 对不起英语不好

I don't think sessions are shared across sub-domains. 我不认为跨子域共享会话。 Instead assign the value of the session to a cookie. 而是将会话的值分配给cookie。 The cookies are shared. Cookie是共享的。

setcookie("TestCookie", $value, time()+3600);

get the value of the cookie by using this: 使用以下方法获取Cookie的值:

$_COOKIE['TestCookie'];

Solved. 解决了。

I created .htaccess file with this content: 我使用以下内容创建了.htaccess文件:

php_value session.cookie_domain ".example.com"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM