This article mainly introduces the ThinkPHP framework's solution to the cross-origin session problem. if you need it, you can refer to ThinkPHP's session cross-origin problem. many developers have encountered it!
In fact, whether it is ThinkPHP or php, you need to set session. cookie_domain when solving session cross-domain problems.
In ThinkPHP, you need to modify the configuration file conf/config. php
Add:
Ini_set ('session. cookie_domain ', ".domain.com"); // Cross-origin access session
After summary, the main solutions to the cross-domain session problem are as follows:
First case: if the file. htaccess does not exist in your Directory, that is, the url is not pseudo-static, add the following to the first line of conf/config. php:
Ini_set ('session. cookie_domain ', ".domain.com"); // Cross-origin access session
If debugging is enabled, it may be used! However, if debugging is disabled, it may not work!
Case 2: If your directory contains the. htaccess file, add the following to the first line of index. php in the root directory:
<? Php ini_set ('session. cookie_domain ', ".domain.com"); // Cross-origin access Session // define the ThinkPHP framework PATH define ('think _ path','/ThinkPHP /'); // define the project NAME and PATH define ('app _ name', 'WWW '); define ('app _ path ','. '); // load the framework entry file require (THINK_PATH. "/ThinkPHP. php "); // instantiate a website application instance App: run ();?>
This method works no matter whether debugging is enabled or not!