Welcome Guest, Not a member yet? Register   Sign In
Sessions
#1

[eluser]Silentman[/eluser]
This is probably a really simple question but here is my problem.

Brief -
I have the sessions database setup and its working great. I am using the freak auth code that has been tweeked a bit. The problem is when I log in it checks first to see if there is a session for the user if so then I have it checking if the user is activated.

Problem -
In the database if I delete all the sessions the users can still log in and it just recreates the session. I guess if it does that I don't see the point of the sessions being stored in the database. Ideally I would like it so when I delete the sessions in the database it will make the user re-log in.

Is what I am experiencing the normal behavior?

Thanks
#2

[eluser]WanWizard[/eluser]
That's how sessions work. Sessions are used to maintain (or create the illusion of) state in a stateless environment.

Sessions work automatic and in the background, there is nothing you should do about it. The session library will make sure there is always a session available.

Normally the flow is:
Code:
// a variable to store form data
$data = array();

// load the user model
$this->load->model( 'user_model' );

// do we have a user_credential in the session
if (  $this->session->userdata('user_credential' )
{
    // restore the user session
    $this->user_model->restore_loggedin_state();
}

// do we still have a user_credential in the session?
// the model could have detected a failure and logged us out!
if (  $this->session->userdata('user_credential' )
{
    // load the logout form
    $data['login_panel'] = $this->load->view('logout', TRUE);
}
else
{
    // load the login form
    $data['login_panel'] = $this->load->view('login', TRUE);
}

// load the page view
$this->load->view('page', $data);

In an application you would probably want to split the processing, and do the checking and the prepwork in a MY_Controller extension, so it happens automatically for every page request. Your user_model could then contain methods like is_logged_in(), on which you can base actions in your controllers.

If you want to log this user out, all you have to do is to delete the "user_credential" variable from the session. The user will be logged out at the next page request (and you can help him with that by redirecting after the logout).
#3

[eluser]Silentman[/eluser]
Giving the user control of the cookie doesn't that create a security risk though? Yeah I do have it set to encrypt it but that still worries me. Should I not be worried about the security using this method?

I guess I just dont understand why use the database if all its going to do is make itself contain everything the cookie does. You delete the session out of the database it just re-creates itself with the data from the cookie. Seems like extra work for nothing.




Theme © iAndrew 2016 - Forum software by © MyBB