0
votes

Trying to load Session library in Codeigniter. It seems to be clearly right but actully don't work. Here's a part of config file:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;

As well, ncryption key variable has already set. Moreover, CI 3 documentation can't give me the way to solve this problem.


I've tried to:

  1. Set 'sess_save_path' variable to 'ci_sessions'
  2. Check folders permissions
  3. Check if table 'ci_sessions' exists
  4. Use Autoloader class
  5. Use class name with capital S

It's strange a little, but config says:

 /*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/www folder
| or in your application/www folder.
|
| Prototype:
|
|   $autoload['www'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
|   $autoload['www'] = array('user_agent' => 'ua');
*/

And here's a code of autoloader:

// Load www
        if (isset($autoload['www']) && count($autoload['www']) > 0)
        {
            // Load the database driver.
            if (in_array('database', $autoload['www']))
            {
                $this->database();
                $autoload['www'] = array_diff($autoload['www'], array('database'));
            }

            // Load all other www
            foreach ($autoload['www'] as $item)
            {
                $this->library($item);
            }
        }
2
I've reinstalled CI but it nothing have changed - user2534629
why do you have $config['sess_save_path'] = NULL; ? , have you tried $config['sess_save_path'] = 'ci_sessions' ? - CodeGodie
have you set your encryption key? $config['encryption_key'] = 'anything_here'; - CodeGodie
what is it doing there? for CI3, It should be in : \system\libraries\Session\Session.php - CodeGodie
thats weird, because your comments say $autoload['www'] ... Where did you download this from? did you do it from codeigniter.com? - CodeGodie

2 Answers

0
votes

You need to do it on

config/autoload.php file and make sure you have this to load the session in Code Igniter 3.

$autoload['drivers'] = array('session');

Make sure you have ci3 installed properly and none of the library files and classes aren't missing. I like using git or composer when installing ci to track changed or you can get the zip or .gz and extract it to use.

0
votes

Here's a list of what you should try:

  1. Make sure you load the session library in autload.php: $autoload['libraries'] = array('session');

  2. Make sure your encryption key is set in cofing.php: $config['encryption_key'] = 'anything_here'

  3. Make sure your database table is named ci_sessions and your sess_save_path is set to that name: $config['sess_save_path'] = "ci_sessions"

  4. If you are on Unix/Linux, make sure to load your library with capital letters: $autoload['libraries'] = array('Session');

  5. If nothing works, check that you download and install the right CI3 files from http://www.codeigniter.com/download