views:

157

answers:

1

Its been a few months since I've seen any questions regarding this, but I wonder if anyone yet has found a solution / written a helper / model to solve this dilemma inside Code Igniter, rather than stray outside of its built-in sessions.

Essentially, a login form is provided for the user, where they will enter their username or e-mail address, and a password. A "Remember Me" checkbox is also provided to the user, which would act to extend the duration of their login.

The problem with CodeIgniter's sessions is (A) they don't expire when you close the browser, and (B) you can't change the length of the session in a user-to-user fashion, but only globally (in my experience).

I suppose with a cookie model / helper there would be a way to add some additional management to these sessions. However, before I go about the trouble of drawing this process out, I'd like to know if anyone else has done something in this area and could offer some code / logic in terms of CodeIgniter. I've written Cookie/Session-based login systems before, but CodeIgniter is providing a slight dilemma in this area.

Any help would be appareciated!

A: 

I'm sorry to say this, but CodeIgniter's sessions are insane. It does not store the sessions on the server, it stores them in a cookie. My advice would be to use native PHP sessions instead (not sure if there's plugins for this). These are then stored on the server side. You can use the session_set_cookie_params function to (conditionally) extend the cookie's lifetime conditionally.

While my answer is not CodeIgniter-specific, I hope it's of use.

EDIT: this page in the user guide mentions how to store sessions in the DB.

igorw
The configuration file easily allows you to store the sessions in the database (server side!) instead of the cookie.However, many still have your concerns and, as you alluded to, there are plugins to use native sessions amongst others.
Kurucu
Fair enough, it allows you to change it to a db-store, I added a note to the answer. But I am still not convinced that is better than native sessions. Would you mind providing links to such plugins? I will make this a community wiki.
igorw
Yeah... probably going to write a class that'll use native sessions / cookies.
LinuxGnut