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!!!.

  • 写回答

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. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决