dtml3340
2012-08-07 07:09
浏览 127

在codeigniter中调用ajax后重新生成新的会话ID

I develop following js in my view.

var url       = '<?php echo base_url(); ?>edit/';
$(document).ready(function(){
    $("#ajax-loader").hide();
    $("#personaldetails-en-di-icon").click(function(){
        $("#ajax-loader").show();
        $.post(url+'ajax/personaldetails/enable', {}, function(data){
            console.log(data);  
        });
     });
});

so,when I click ,it request edit controller.

in edit controller I have private $id = null;

public function __construct() {
    parent::__construct();
    $this->load->library('session');
    $this->load->library('input');
    $this->load->model('editcv_model');
    $this->load->helper('url');

    $this->id = $this->session->userdata('login');        
    if (intval($this->id) < 1)
        die(json_encode(array('response' => 'not logged in')));
    }

    public function _remap($method = '',$param = array()){
        echo (json_encode(array('response' => 'done')));
    }
}

the first ajax call echo {"response":"done"} in chrome console,but second and other request echo {"response":"not logged in"}. when I check session table in phpmyadmin,it will regenerate session id,with other user-agent

enter image description here

as you seen Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.57 Safari/537.1 AlexaToolbar/alxg-3 changed to Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) AlexaToolbar/alxg-3.0 in ajax request.but I use ubuntu with google chrome browser!!!.

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

我在视图中开发了以下js。

  var url  ='&lt;?php echo base_url();  ?&gt;编辑/'; 
 $(文件).ready(function(){
 $(“#ajax-loader”)。hide(); 
 $(“#personaldetails-en-di-icon”  ).click(function(){
 $(“#ajax-loader”)。show(); 
 $ .post(url +'ajax / personaldetails / enable',{},function(data){
 console  .log(数据); 
}); 
}); 
}); 
   
 
 

因此,当我点击时,它会请求编辑控制器。< 编辑控制器中的/ p>

我有 private $ id = null;

  public function __construct(){
 parent :: __ construct(  ); 
 $ this-&gt; load-&gt; library('session'); 
 $ this-&gt; load-&gt; library('input'); 
 $ this-&gt; load-&gt; model  ('editcv_model'); 
 $ this-&gt; load-&gt; helper('url'); 
 
 $ this-&gt; id = $ this-&gt; session-&gt; userdata('login')  ;  
 if(intval($ this-&gt; id)&lt; 1)
 die(json_encode(array('response'=&gt;'未登录'))); 
} 
 
公共函数_remap  ($ method ='',$ param = array()){
 echo(json_encode(array('response'=&gt;'done'))); 
} 
} 
   
 
 

Chrome控制台中的第一个ajax调用echo {“response”:“done”} ,但第二个和其他请求echo {“response”:“not 登录“} 。 当我在phpmyadmin中检查会话表时,它将使用其他用户代理重新生成会话ID

如您所见 Mozilla / 5.0(X11; Linux i686)AppleWebKit / 537.1( KHTML,如Gecko)Chrome / 21.0.1180.57 Safari / 537.1 AlexaToolbar / alxg-3 更改为 Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 6.0)AlexaToolbar / alxg-3.0 ajax request.but我使用ubuntu和谷歌浏览器浏览器!!!。

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

1条回答 默认 最新

  • dqcz57269 2012-08-09 14:01
    已采纳

    i also had the same problem with CodeIgniter sessions.

    i switched to native sessions: https://github.com/EllisLab/CodeIgniter/wiki/Dariusz-Debowczyk's-Session-Class

    i never really understood the reasoning behind implementing yet another session mechanism (i am not talking about the CI_Session) when php has a good one already. :)

    点赞 打赏 评论

相关推荐 更多相似问题