We are going to extend the Session library to use native PHP sessions instead of being cookie based.
Before we start to create the library, we need to know how to extend libraries. All CodeIgniter classes are prefixed with CI_
- and all our extended classes should be prefixed with MY_
- this is configurable, just open up your config.php
file and edit the following line:
$config['subclass_prefix'] = 'MY_';
Our filename needs to be MY_Session.php
(or whatever you set your prefix to be) and the class will be MY_Session
and it will extend CI_Session
. When loading the class, though, we don't need to use the prefix; we simply use session
and CodeIgniter will load the extended class for us.
We could completely replace the class by leaving out the extends
clause on our class declaration—but we don't want to do that as we don't want to overwrite the flash data functionality. This library will work in exactly the same way as the CodeIgniter Session Class: we don't change the way we...