Home  >  Article  >  Backend Development  >  ThinkPHP框架实现session跨域问题的解决方法_PHP教程

ThinkPHP框架实现session跨域问题的解决方法_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:26:28795browse

ThinkPHP的session跨域问题很多开发者都遇到过!
其实不管是ThinkPHP还是php本身,在解决session跨域问题的时候都需要设置session.cookie_domain。
在ThinkPHP里,需要修改配置文件conf/config.php
在第一行加上:

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

经过总结,针对session跨域这一问题的解决方法主要有以下几种:

第一种情况:如果你目录下没有.htaccess这个文件,也就是没有采取url伪静态的话,那么,你在conf/config.php的第一行加上:

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

这种如果你开启了调试,可能用!但关闭了调试,可能就不管用了!

第二种情况:如果你目录下有.htaccess这个文件,那么你在根目录,index.php的第一行加入:

<?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();
?>

这种方法不管开不开启调试都管用!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/824682.htmlTechArticleThinkPHP的session跨域问题很多开发者都遇到过! 其实不管是ThinkPHP还是php本身,在解决session跨域问题的时候都需要设置session.cookie_domain。 在...
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