dstew32424 2013-09-16 16:42
浏览 53
已采纳

在codeigniter中设置会话加载

I understand codeigniter sets up sessions for you if you load the library. However, I want to have my own set of rules. I thought I could do it by adding userdata and checking to see if its exists on each page load. However, its not working...

Here is my welcome controller...

class Welcome extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        //$this->output->enable_profiler(TRUE);

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->helper('url');
    }

    function index($cliqid='', $cliq=false)
    {
        $default_cliq = 5; //this equals whatever the user sets
        $this->page_m->load_session($default_cliq); //check to see if session is new; if so, perform list of actions
        //$this->session->sess_destroy();
        print_r($this->session->all_userdata());
    }
}

It points to page_m which consists of the load session method where I want to apply some session variables to be used throughout the visitor's stay on the page:

Here is a brief excerpt:

class Page_m extends CI_Model
{
function __construct()
{
    parent::__construct();
    $this->load->model('cliq_info_m');
}

function load_session($default_cliq)
{
    //check if session is new
    if ($this->session->userdata('exists') == true) {
        //the list of things to do
        $this->record_session();   //check if ip exists in DB, if not, record     
        $this->cliq_info_m->change_active($default_cliq);

        //make session old
        $data['exissts'] = true;
        $this->session->set_userdata($data); 
    } else {
        return false;
    }
}

What happens...is it runs this every time, regardless of the 'exists' variable.

Anyone know why? And a possible solution?

  • 写回答

1条回答 默认 最新

  • dongmale0656 2013-09-16 17:35
    关注

    It appears that the reason for the error was the fact that I had heading errors (echoing the script alert). Once i removed all that, it started working...

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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置