Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Session Data not available in other pages after login
#1

[eluser]jswat[/eluser]
So, I have set up a login page that verifies the user's credentials, and then sets codeigniter session data 'email' and 'is_logged_in' and a few other items. The first page after the login, the data is accessible. After that page, I can no longer access the session data. In fact, if I try reloading that first page, the session data is gone.

I have tried storing it in the database, storing it unencrypted (bad idea I know, but it was for troubleshooting), and storing it encrypted. I have autoloaded the session library in config.php.

Here's an example of the code I'm using to set the session data:

Code:
$data = array(
                    'email' => $this->input->post('username'),
                    'is_logged_in' => true
                );
                $this->session->set_userdata($data);


And to retrieve it, I'm using :

Code:
$this->session->userdata('email');


Or

Code:
$this->session->userdata('is_logged_in');


I've done lots of work with PHP and cookies, and sessions before, but this is my first project with Codeigniter and I'm perplexed.

Could it have something to do with directory issues? I have the login page and process controlled by a 'login' controller, and then it redirects to a 'site' controller.

Thanks for your help, and please let me know if I need to clarify anything.
#2

[eluser]Eric Cope[/eluser]
When you store the data in the database unencrypted, is the data viewable on the first page? On the second page?

This happened to me when I used cookies for multiple sites using the same CI installation. Each installation was overwriting the other site's unique cookie id. I had to add a cookie prefix to fix that.

It could have something to do with directory, but I suspect you would get other errors.
#3

[eluser]jswat[/eluser]
To answer your first question, it shows up on the first page, but not the second. And in fact, if I refresh that first page, the data is no longer accessible. So it appears to be only accessible to the page right after the session data is set.

I don't have any other codeigniter installations currently using cookies on the server, so that is not the issue.

I actually ended up installing the Native Session library and everything seems to work now. Not sure what the issue was.




Theme © iAndrew 2016 - Forum software by © MyBB