1

I set a session variable in my login controller after successful login. When I check for the variable in my dashboard controller no session data is found.

When I check the session in the login controller, session data exists. It does not exist when I check the dashboard controller. I have also tried using database sessions with no success.

I am using CodeIgniter 3.1.3 with HMVC (Module Based MX Controller). Code and screenshots of my current issue follow.

My Config File for Session

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Attachment 1

enter image description here

Attachment 2

enter image description here

Attachment 3

enter image description here

Attachment 4

Blockquote

enter image description here

Steve Buzonas
  • 5,300
  • 1
  • 33
  • 55
Md. Himel Ali
  • 301
  • 2
  • 10

3 Answers3

0

print_r($_SESSION) doesn't works in CI. In Codeigniter we have to write following syntax.

print_r($this->session->userdata); 

or

print_r($this->session->all_userdata());
Bhavin
  • 2,070
  • 6
  • 35
  • 54
0

If you didn't load session library form, you need to load first. Try this way.

$this->load->library('session');
$this->session->userdata('your_session_variable'); // get single value
or
print_r($this->session->userdata);
or
print_r($this->session->all_userdata()); // get all session data but deprocated in newer version
Abdullah Al Shakib
  • 2,034
  • 2
  • 15
  • 16
  • $this->load->library('session'); loaded by autoload.php and try both print_r($this->session->userdata); or print_r($this->session->all_userdata()); same problem occur.. – Md. Himel Ali Mar 13 '17 at 06:08
  • use native session driver in stead of files. $config['sess_driver'] = 'native' and then check. If it works, then check file permission of APPPATH . 'cache/' have write access and then change $config['sess_driver'] = 'files' – Abdullah Al Shakib Mar 13 '17 at 06:26
  • For your kind consideration, When I start my computer it's work fine. After many time used in my loaclhost this problem has been shown. Then browser history and coockie has remove then works fine. It is not only in my computer, 3 computer are shown this problem. – Md. Himel Ali Mar 13 '17 at 06:38
0

You probably miss to load session library in Dashboardcontroller.So load it first using:

class Dashboardcontroller extends CI_Controller{
function __construct(){
    $this->load->library('session');//loads session library
}

Then try to

 print_r($_SESSION)

OR

print_r($this->session->all_userdata());
Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19