Home > php教程 > PHP开发 > ThinkPHP framework implements session cross-domain solution

ThinkPHP framework implements session cross-domain solution

高洛峰
Release: 2016-12-22 10:44:41
Original
1148 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 in the first line:

ini_set('session.cookie_domain', ".domain.com");//跨域访问Session
Copy after login

After summary, the main solutions to the problem of cross-domain session are as follows:

The first case: If there is no .htaccess file in your directory, that is, if the url is not pseudo-static, then you add:

ini_set('session.cookie_domain',".domain.com");//跨域访问Session
Copy after login

in the first line of conf/config.php. If this is the case You have enabled debugging, it may work! 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:

Copy after login

This method works regardless of whether debugging is turned on or not!

For more related articles on solutions to the cross-domain problem of sessions implemented by the ThinkPHP framework, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template