Welcome Guest, Not a member yet? Register   Sign In
New to CI, I need help with member area - sessions

I’m all new to CI, what I’ve seen so far is really nice!

I have started to try things out. The first problem I have is about sessions. I want a member to be able to login (then starting a session), and for each member page I have to check the session to see that its a loged in user, otherwise redirect. How do I do this in a proper way? Is there anyone having a sample application that handles this?


If you autoload the session library, a session is actually started for every unique visitor.

Then, in your code, you can mark a unique user as logged in once they have succesfully completed and submitted your login form, with
$this->session->set_userdata('userid', $user_id_from_authentication);

Somewhere in your members area controller, you can:
if( $this->session->userdata('userid') === FALSE )

The session library (or is it a helper?) returns false if a userdata variable has not been set, hence the code above. When a user logs out be sure to unset 'userid' and/or any other variables you set for the user session.

What I would suggest is that you at least turn on cookie encryption, and preferably database variable storage. The least information sent about authentication over the network, the better.

Theme © iAndrew 2016 - Forum software by © MyBB