CodeIgniter 3 Session: File Driver

My first production web application was built using codeigniter. At that time Elislab maintained the codeigniter.Now it is maintained by British Columbia Institute of Technology and they have released the version 3.Recently I started to do a project from new version (3.0.1). I like the new documentation.

New configurations are introduced in this new version. According to user guide Session library is rewritten. Now session driver supports:

  • files
  • database
  • redis
  • memcached

So I moved easy but slower driver: files. But it was not that easy. This was my configuration in beginning.

1
2
3
4
5
6
7
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'my_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'application/session/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

This gives me a error

1
2
3
4
5
6
7
8
A PHP Error was encountered
Severity: Warning
Message: touch(): Unable to create file appication/session\my_sessioncd4ae6896742753a1be557173803165c221e0aff
because No such file or directory
Filename: drivers/Session_files_driver.php

So I changed the 'sess_save_path' to APPPATH.'session/'. Since Documentation says ‘WARNING: Only absolute paths are supported!’

1
2
3
4
5
6
7
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'my_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH.'session/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

FYI : When i writing this blog 'sess_save_path' to '/application/session/' this also worked. But I suggest to use APPPATH since it asks for absolute path.

Share Comments