简体   繁体   English

PHP:将Cookie域转换为子域

[英]PHP: Convert a cookie domain for a subdomain

My actual situation 我的实际情况

http://www.stackoverflow.com/project1

For this i use this session configuration (the session must be active for up to one hour, and be valid only on the folder /project1 ) 为此,我使用了此会话配置(会话必须处于活动状态最多一小时,并且仅在文件夹/ project1上有效)

$lifetime = 3600;
session_start();
setcookie(session_name(),session_id(),time()+$lifetime,"/project1");

Soon i'll have to move the /project1 in a subdomain 很快我将不得不将/ project1移到子域中

http://project1.stackoverflow.com

How do i change the session to be valid only in the subdomain project1 ? 如何将会话更改为仅在子域project1中有效? thanks 谢谢

I suggest you stop managing the Session cookie manually like this, and let PHP handle it automatically for you. 我建议您停止像这样手动管理Session cookie,并让PHP为您自动处理。

You can set the path, domain, expiry etc for the session cookie with the function session_set_cookie_params 您可以使用函数session_set_cookie_params设置会话cookie的路径,域,有效期等。

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

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