2017-01-10 06:12
浏览 52


I'm using a domain like and a sub-domain like

I'm trying to call the Login function of In the end I cant set the session of for future functions to be called.

I'm using CodeIgniter in my sub-domain and my root domain just has an HTML page with native JavaScript. I wanted to use as my endpoint for all my sub-websites.

I tried changing the config of my subdomain(CI) to

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;

and also the index.php file of my to:

session_set_cookie_params(0, '/', '');

图片转代码服务由CSDN问答提供 功能建议

我正在使用像 这样的域和一个子域 比如

我正在尝试调用sub.example.com的 Login 函数。 最后我无法设置sub.example.com的会话以便将来调用函数。

我在子域中使用CodeIgniter而我的根域只有一个HTML页面 使用原生JavaScript。 我想使用 作为我所有子网站的终端。

我尝试将子域(CI)的配置更改为< / p>

  $ config ['cookie_prefix'] =“”; 
 $ config ['cookie_domain'] =“。”; 
 $ config ['cookie_path']  =“/”; 
 $ config ['cookie_secure'] = FALSE; 


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyi5425 2017-01-10 10:34

    I solved my problem by setting header("Access-Control-Allow-Credentials: true");[SERVER-SIDE] and $http.defaults.withCredentials = true;[CLIENT-SIDE] using Angular $httpProvider upon request

    And also don't forget to set the header("Access-Control-Allow-Origin:");[SERVER-SIDE] my root domain to have an access to my sub-domain.

    but if you have multiple domains/sub-domains to allow you can use below code

    $http_origin = $_SERVER['HTTP_ORIGIN'];
    if ($http_origin == "" || $http_origin == "" || $http_origin == "")
        header("Access-Control-Allow-Origin: $http_origin");

    for more info Access-control-allow-credentials

    点赞 打赏 评论
  • dsla94915 2017-01-10 06:21

    In codeigniter you not need to session_start();.Just load session library and then try .

    Load session library as:

    $this->load->library('session');//from models,controllers and view..

    But if you are outside from models,views and controller..Load CI session library as follows:

    1.First create instance of CI

    $this->CI =& get_instance();

    2.Then Load Library


    For more see here

    点赞 打赏 评论

相关推荐 更多相似问题