Which session library should I use with CodeIgniter?

I recently started using CI and with it CI sessions, but I noticed that one thing in particular is much more time consuming for CI sessions than for basic PHP sessions: arrays.

I have an array of data that is saved regardless of logging in / out of the system called $_SESSION['stats'] , then I save the data in this array in the form:

$_SESSION['stats']['last_page'] = $_SERVER['REQUEST_URI']; .

And when the user logs out, he saves the statistics array in a variable, clears the session and then loads it back into the new session.

The problem is that to edit the key last_page instead of one line above I have to use this code:

 $stats = $this->CI->session->userdata('stats'); $stats['last_page'] = $_SERVER["REQUEST_URI"]; $this->CI->session->set_userdata('stats', $stats); 

This is one of the many troubles that I find in CI sessions that make me feel unsatisfied with it as a session handler. So my question is: which session system should I use with CodeIgniter? ... is there any reason to use CI sessions? Is there a CI library you would suggest? Why not just use PHP sessions?

Thanks,

Lemiant

+4
source share
2 answers

CI sessions offer some additional features: such as automatic recovery of the session identifier for each specified period of time (for security), IP address tracking and flashdata (session data that is cleared after reading it once).

The CI session engine saves all data in a cookie. The PHP engine of the native session is stored on the server side. Each has its own advantages / disadvantages. Cookies can contain only 4 Kbytes of data, so if you store large amounts of data in PHP session sessions, it might be better.

If you decide you want to use your own PHP sessions, use: Session Hybrid (CI 1.7.2)

Session Hybrid uses its own PHP sessions, can store session data in standard CI db, is a replacement for replacing the CI session class and only requires rewriting a single file.

[* If you are using CI version before version 1.7.0, try PHPSession and Native Session ]

Note: if you decide to stay with CI sessions , for additional protection you can store sessions in the database and encrypt cookies (see Session Settings ).

+7
source

It looks like you are using the breadcrumbs method.

This may help, http://codeigniter.com/forums/viewthread/137949/

And to answer your other question, yes, there is a very good reason to use the CodeIgniter session library. I use it because I need to store user session data in my database (safer), and the library comes with the option of encrypting cookies and if global XSS filtering is enabled, then the data will also be cleared.

0
source

All Articles