when I want to set session data in codeigniter 3 it says error like:
A PHP Error was encountered
Severity: Warning
Message: mkdir(): Invalid path
Filename: drivers/Session_files_driver.php
Line Number: 117
Backtrace:
File: C:\xampp\htdocs\ci-test\application\controllers\login.php
Line: 7
Function: __construct
File: C:\xampp\htdocs\ci-test\index.php
Line: 292
Function: require_once
Here is the code that where want to set session data.
$sess_array = array(
'id' => 1,
'username' => 'bikramkc.kc@gmail.com'
);
$this->session->set_userdata($sess_array);
Sharing a solution that helped me, try set your config variable like:
$config['sess_save_path'] = sys_get_temp_dir();
change your application->config->config.php and set
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
& Run SQL query
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (id),
KEY `ci_sessions_timestamp` (`timestamp`)
);
In config.php sess_save_path
should be sys_get_temp_dir();
then it will resolve the error of mkdir(): Invalid path
The reason you encountered the error is because you didn't have a $config['sess_save_path']
Go to you config.php
and set
$config['sess_save_path'] = NULL;
It can be due to PHP and codeIgniter version.
For me, PHP 7.1.25 and CI 3.0.4 didn't work. You can check with session_id(). Session was refreshed.
With CI 3.1.2 it works.
Try this in your config.php
$config['sess_save_path'] = NULL
If $config['sess_save_path']
is sys_get_temp_dir()
then session data will store in system folder.
And If you have database table as ci_sessions with below config.php:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
The data will store in database. In this case you can $config['sess_save_path'] = NULL;