Search in This Blog

session destroyed after redirect in codeigniter

Problem:

Working CodeIgniter framework you can face the session problem. the problem is when you storing the values in session and redirect the page. then session destroyed automatically, it is loosing session data even you have properly loaded session library $this->load->library('session') in constructor.

see the below code:

public function myset() 
{
        $this->session->set_userdata('mydata', 'data');
        redirect('/', 'refresh');
}


function index()
{
          // loosing here data
          $mydata = $this->session->userdata('mydata');

}






Solution:

As we are seeing many new frameworks are coming today. but the Mother and base of all frameworks is Core PHP,  So we must have good knowledge about Core PHP. Here I have solved this session problem by Core PHP.

Example:

session_start();
public function myset() 
{
        $_SESSION['mydata']='data'
        redirect('/', 'refresh');
}


function index()
{      $mydata='';
        if(isset($_SESSION['mydata']) && !empty($_SESSION['mydata'])) {
                  $mydata= $_SESSION['mydata']);
        }

}

Previous
Next Post »