codeigniter 3提取会话ID的问题

时间:2016-05-31 05:30:38

标签: codeigniter

我想要检查会话并获取当前用户的详细信息,我在这里新增了一行plz help

   public function profile() {
        $this->load->view('header');
        $this->load->model('brid_groom_fetch');
        $this->session->userdata('uname');

        //This  below line fetch model db data
        $row = $this->brid_groom_fetch->get_program_specific_gender();

        //here i have check data is in session..
        $session_id = $this->session->userdata(
         array('uname' => $row->uname));
         print_r($sesid);
    }

2 个答案:

答案 0 :(得分:0)

为什么不使用基本的==运算符?

public function __construct() {

    parent::__construct();
    $this->load->model('brid_groom_fetch');

    // you need to load session library
    // Have you loaded ?
    $this->load->library('session');
}


public function profile() {

    $this->load->view('header');

    // you do not need to load in all method.
    // we have already loaded in __construct()
    // $this->load->model('brid_groom_fetch');

    // use variable 
    $uname = $this->session->userdata('uname');

    //fetch data from db
    $row = $this->brid_groom_fetch->get_program_specific_gender();

    if ($row->uname == $uname) {
        $session_id = $this->session->userdata('session_id');
        var_dump($session_id);
    }
 }

答案 1 :(得分:0)

您正在使用

设置userdata
$this->session->set_userdata(array('uname' => $yourname));

$this->session->set_userdata('uname',$yourname);

要检查用户数据中设置的值,您需要使用

$sess_name = $this->session->userdata('uname');
print_r($sess_name);

然后验证您收到的$ sess_name。 您也可以使用

取消设置用户数据
$this->session->unset_userdata('uname');