Home > Backend Development > PHP Tutorial > ThinkPHP framework implements session cross-domain solution_PHP tutorial

ThinkPHP framework implements session cross-domain solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:26:28
Original
961 people have browsed it

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
Copy after login

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.php
ini_set('session.cookie_domain',".domain.com");//跨域访问Session
Copy after login

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:

<&#63;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();
&#63;>
Copy after login

This method works regardless of whether debugging is enabled or not!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824682.htmlTechArticleThinkPHP’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...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template