Thinkphp Framework for solving the problem of Session cross-domain _php example

Source: Internet
Author: User

Thinkphp's session Cross-domain problem many developers have encountered!
In fact, whether it is thinkphp or PHP itself, in the resolution session Cross-domain problems need to set the Session.cookie_domain.
In thinkphp, you need to modify the configuration file conf/config.php
In the first line, add:

Ini_set (' Session.cookie_domain ', ". domain.com");//cross-domain Access session

After summing up, the solution for the session Cross-domain problem is mainly as follows:

The first case: if you do not have a directory under the htaccess this file, that is, do not take URL pseudo static, then you in the first line of conf/config.php Plus:

Ini_set (' Session.cookie_domain ', ". domain.com");//cross-domain Access session

This can be used if you turn on debugging! But if you turn off debugging, it may not work!

Second: If you have a. htaccess this file, then you add the first line in the root directory, index.php:

<?php ini_set (' Session.cookie_domain ', '. domain.com ');//cross-Domain Access session
//Definition thinkphp Framework path
define (' Think_ PATH ', '/thinkphp/');
Define project name and path
define (' app_name ', ' Www ');
Define (' App_path ', '. ');
Load frame Entry file
require (Think_path.) /thinkphp.php ");
Instantiate a Web application instance
app::run ();
? >

This method will work regardless of whether the debugging is open 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.