CodeIgniter Forums
Session lost after redirect - 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: Session lost after redirect (/showthread.php?tid=67978)

Pages: 1 2


Session lost after redirect - jaimealvarezv - 05-03-2017

I need help for this issue:

Code:
function login_validation() {
    $this->load->library('session');
    
    
    $this->session->set_userdata('session_nickname', $this->input->post('nickname', TRUE));
    var_dump($this->session->userdata('session_nickname'));  // PRINTS the nickname OK
    redirect('/main/dashboard');
}

function dashboard() {
    $this->load->library('session');
    var_dump($this->session->userdata('session_nickname'));  // PRINT NOTHING
}


Te issue is I lost all my session vars after the redirect, in function login_validation the value printed is correct but in function [font=Monaco, Consolas, Courier, monospace]dashboard no.[/font]

My config file is:


Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

[font=Monaco, Consolas, Courier, monospace]Any Ideas? I'm desperate. Thank you in advance.[/font]


RE: Session lost after redirect - InsiteFX - 05-03-2017

Autoload the session library


RE: Session lost after redirect - jaimealvarezv - 05-03-2017

(05-03-2017, 12:27 PM)InsiteFX Wrote: Autoload the session library

Thank you for your response. 

I have read all the posts related to this issue but I cannot find any solution. 

Code:
$this->session->set_flashdata('session_nickname', 'some message');

but in the dashboard function after getting values from session it prints an empty string.

I hope to solve this issue

Thank you


RE: Session lost after redirect - jaimealvarezv - 05-03-2017

The session lib is currently added to the autoload


RE: Session lost after redirect - donpwinston - 05-03-2017

Some ideas:
Check the log for any info.
Try it with the session set to the default file system instead of the database.


RE: Session lost after redirect - jaimealvarezv - 05-03-2017

I am sorry, I forgot to say that I tried with file sessions instead of database sessions. I got the same result.


RE: Session lost after redirect - jagad89 - 05-03-2017

(05-03-2017, 02:01 PM)jaimealvarezv Wrote: I am sorry, I forgot to say that I tried with file sessions instead of database sessions. I got the same result.

Do you have multiple redirection ?


RE: Session lost after redirect - InsiteFX - 05-04-2017

If multiple redirects then you will need to use keep_flashdata()


RE: Session lost after redirect - marksman - 05-04-2017

do login_validation and dashboard belongs to same class? would you show us your controller class?


RE: Session lost after redirect - donpwinston - 05-04-2017

You'd don't need to execute " $this->load->library('session');" twice. Put it in the controller's constructor. Make sure you call parent::__constructor() first. If using autoload then don't call it at all.