• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get session at multiple controllers

#1
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()
 }

Reply

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

You should then be able to access your session data from anywhere in the application.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.