有三种解决方法:
1.只要在php页面的最开始(要在任何输出之前,并且在session_start()之前)的地方进行以下设置
ini_set('session.cookie_path', '/');
ini_set('session.cookie_domain', '.mydomain.com');
ini_set('session.cookie_lifetime', '1800');
2.在php.ini里设置
session.cookie_path = /
session.cookie_domain = .mydomain.com
session.cookie_lifetime = 1800
3.在php页面最开始的地方(条件同1)调用函数
session_set_cookie_params(1800 , '/', '.mydomain.com');
我的解决方法是在入口出添加如下代码:
ini_set('session.cookie_path', '/');
ini_set('session.cookie_domain', '.domain.com'); //注意domain.com换成你自己的域名
ini_set('session.cookie_lifetime', '1800');
如图: