Welcome Guest, Not a member yet? Register   Sign In
Session lost after redirect
#1

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 dashboard no.

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;

Any Ideas? I'm desperate. Thank you in advance.
Reply
#2

Autoload the session library
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply
#4

The session lib is currently added to the autoload
Reply
#5

(This post was last modified: 05-03-2017, 01:52 PM by donpwinston.)

Some ideas:
Check the log for any info.
Try it with the session set to the default file system instead of the database.
Simpler is always better
Reply
#6

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

(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 ?
Reply
#8

If multiple redirects then you will need to use keep_flashdata()
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

do login_validation and dashboard belongs to same class? would you show us your controller class?
God Bless CI Contributors Smile
Reply
#10

(This post was last modified: 05-04-2017, 05:42 AM by donpwinston.)

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.
Simpler is always better
Reply




Theme © iAndrew 2016 - Forum software by © MyBB