Home  >  Article  >  php教程  >  ThinkPHP framework implements session cross-domain solution

ThinkPHP framework implements session cross-domain solution

高洛峰
高洛峰Original
2016-12-22 10:44:411107browse

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

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

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:

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!

Statement:
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