ThinkPHP’s session cross-domain problem has been encountered by many developers!
In fact, whether it is ThinkPHP or PHP itself, session.cookie_domain needs to be set when solving session cross-domain problems.
In ThinkPHP, you need to modify the configuration file conf/config.php
Add on the first line:
ini_set('session.cookie_domain', ".domain.com");//跨域访问Session
After summary, the main solutions to the problem of session cross-domain are as follows:
The first situation: If there is no .htaccess file in your directory, that is, if the URL is not pseudo-static, then you add:
to the first line of conf/config.phpini_set('session.cookie_domain',".domain.com");//跨域访问Session
This may work if you enable debugging! But if debugging is turned off, it may not work!
Second case: If there is a .htaccess file in your directory, then you add in the root directory, the first line of index.php:
<?php ini_set('session.cookie_domain',".domain.com");//跨域访问Session // 定义ThinkPHP框架路径 define('THINK_PATH', '/ThinkPHP/'); //定义项目名称和路径 define('APP_NAME', 'Www'); define(‘APP_PATH', '.'); // 加载框架入口文件 require(THINK_PATH."/ThinkPHP.php"); //实例化一个网站应用实例 App::run(); ?>
This method works regardless of whether debugging is enabled or not!