Shakti Sisodiya
Shakti Sisodiya

Reputation: 228

Codeigniter $this->session->set_userdata() not working properly

i am generating a session but when i generate it i am not getting __ci_last_regenerate after calling $this->session->set_userdata('sessionName',$sessionArray) function. when i redirect after generate my session without __ci_last_regenerate the session data is not appearing on next page.i am using CI 3.1.4

$user_basic = array( 
    'user_id' => $user_id, 
    'email' => $this->input->post('email'), 
    'is_user_login' => 'true', 
    'language' => 'eng' 
); 
$this->session->set_userdata('user_basic',$user_basic); 

echo'<pre>';print_r($this->session->userdata());

Thank you

Upvotes: 5

Views: 29513

Answers (4)

Majid Sayyed
Majid Sayyed

Reputation: 297

You need to upgrade codeigniter version from 3.0 to 3.1.x

  1. Download 3.1.x from https://codeigniter.com/userguide3/installation/downloads.html
  2. Copy system folder from this 3.1.x and paste it into your project by replacing current system folder.

This will upgrade the CI version and also session will start working

Upvotes: 0

Nivratti Boyane
Nivratti Boyane

Reputation: 619

If you are using PHP >=7.0 then check your codeignator version.

If codeignator version is 3.0 or less than 3.0 then you need to update codeignator to current version (ex. codeignator current version 3.1.7)

Upvotes: 21

Deb Sharma
Deb Sharma

Reputation: 114

First load the session library :

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

Use it like this :

$this->session->set_userdata($sessionArray)

But it completely depends on the rest of your code. Upload the rest of your code for better olution

Upvotes: 0

user4419336
user4419336

Reputation:

Autoload your sessions in the config/autoload.php $autoload['libraries'] = array('session');

First make sure you have set your session save path. Some think like this example

$config['sess_save_path'] = APPPATH . 'cache/sessions/'; 
$config['sess_regenerate_destroy'] = TRUE;

Folder permissions 0700

Then try and set sessions on controller something like example

$sessionArray = array(
   'is_logged' => TRUE
);

$this->session->set_userdata($sessionArray);

// Remove the sessionName $this->session->set_userdata('sessionName',$sessionArray)

Then you should be able to access session like

<?php echo $this->session->userdata('is_logged');?>

Upvotes: 3

Related Questions