ThinkPHP framework-solution to cross-domain session problems _ php instance

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.