CodeIgniter Forums
How can I get session at multiple controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How can I get session at multiple controllers (/showthread.php?tid=73073)



How can I get session at multiple controllers - nuonuonuo - 03-15-2019

Hi,
I set SESSION at Login.php controller, And I want get SESSION at other controllers,
But at other controllers, I get SESSION have `__ci_last_regenerate: 1552555932` only, No information I have stored in it.
What can I do something get the SESSION?
Thanks!

This is my Login.php controller

PHP Code:
class Account extends CI_Controller
 
{
 
 public function __construct()
 
 {
 
  parent::__construct();
 
  $this->load->model('Account_model');
 
  $this->load->library('session');
 
 }


 
 public function login()
 
 {
 
  $username $this->input->post('username');
 
  $password $this->input->post('password');

 
  // run login model,return array or FALSE
 
  $query $this->Account_model->login($username$password);

 
  if ($query) {
 
   // set SESSION
 
   // $query is array, like this :{'username'=>"bob",'level'=>2}
 
   $this->session->set_userdata($query);
 
   //do something...
 
  }
 
 }


And this controllers, I want use SESSION, but faile

PHP Code:
class Number_record extends CI_Controller
{
 public function 
__construct()
 {
 
 parent::__construct();
 
 $this->load->model('Number_record_model''NRM');
 
 $this->load->library('session');
 }

 public function 
add_num()
 {
 
 // I want get SESSION at this
 
 // But only get this :__ci_last_regenerate: 1552555932
 
 $_SESSION;
 
 $this->session->userdata()
 }




RE: How can I get session at multiple controllers - InsiteFX - 03-16-2019

Load the Session library in ./application/config/autoload.php

You should then be able to access your session data from anywhere in the application.