在null上调用成员函数userdata()

please help me!I don't know how do . I need your help

Message: Call to a member function userdata() on null

Filename: /home/xxxxx/xxxxx.x.it/xxx/application/libraries/Auth.php

Line Number: 23

Backtrace:

( page) Function: get_user

(controller) Function: _costruttor

    function get_user() {
    $name = $this->session->userdata('id');
    if ($name) {
    $this->obj->db->where("id",$this->obj->session->userdata("id"));
        $this->obj->db->where("ip",$this->obj->input->ip_address());
        $user= $this->obj->db->get("u_user")->row_array();
        if ($utente) {
            $this->user = $user;
        }
    }



class MY_Controller extends CI_Controller {
function _costruttor() {
    parent::__construct();
    $this->load->library("encrypt");
    $unlocked = array('login');
    $this->page->get_user();
    $this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file'));
    if (!$this->page->get_user() AND ! in_array(strtolower(get_class($this)), $unlocked)) {
        $this->session->set_userdata('back_url', current_url());
        redirect('login/');
    }
}

}

I think you have forgot to include session library.

There are two ways to solve this:

1) Include session library dynamically in your page.

Insert this

$this->load->library('session');

Before the line.

$name = $this->session->userdata('id');

2) Adding it in autoload libraries:Another way of doing this is:

If you required it globally, include it in

applications/config/autoload.php

$autoload['libraries'] = array('database', 'session');

Assuming that database and session are required globally.

The error is quite simple

Message: Call to a member function userdata() on null


Line Number: 23

Meaning, on line 23 of the file described above, you are doing something among these lines

$this->session->userdata(/* something goes inside here */);

Meaning $this->session is null (it is not instanciated or it doesnt exist in this context. You can confirm this by var_dump($this->session)followed by an exit and if it gives a null, you've found the trouble)