Reputation: 907
Trying authorisation in my first CodeIgniter 2 app. Learning about sessions and I can't understand at what time I must initialise session for a visitor? In a concrete action or maybe in the constructor? As we know, a user can call any action by typing a URL himself. Does it mean that I must have something like before()
method which must be called before all actions and in which I check if the session is available, and if no, start a session?
From these sites I can read about sessions in common, but I'd like some examples on CodeIgniter framework. Maybe authorisation in CodeIgniter is much specific then these ones.
Upvotes: 0
Views: 128
Reputation: 4079
The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie. It can also store the session data in a database table for added security, as this permits the session ID in the user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to use the database option you'll need to create the session table as indicated below.
Note: The Session class does not utilize native PHP sessions. It generates its own session data, offering more flexibility for developers.
Note: Even if you are not using encrypted sessions, you must set an encryption key in your config file which is used to aid in preventing session data manipulation.
Sessions will typically run globally with each page load, so the session class must either be initialized in your controller constructors, or it can be auto-loaded by the system. For the most part the session class will run unattended in the background, so simply initializing the class will cause it to read, create, and update sessions.
To initialize the Session class manually in your controller constructor, use the $this->load->library function:
$this->load->library('session');
More informacion for the CI Sesseion you can read in UserGuide
Thanks a lot
Upvotes: 1