Reputation: 876
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' => '[email protected]'
);
$this->session->set_userdata($sess_array);
Upvotes: 45
Views: 115462
Reputation: 714
This error comes when we use directory bases session approach in CodeIgniter. If we use database based session approach error will go. Use code below -
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`)
);
Upvotes: 17
Reputation: 1925
1.Open the config.php on application/config folder
2.Browse all the way down to the $config['sess_save_path'] = NULL;
line.
3.Change the NULL
value to BASEPATH.'sessions'
Upvotes: 6
Reputation: 1
I had a similar case I have a multihost in godaddy and first I corrected the .htacces file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Then correct the file config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Upvotes: -1
Reputation: 11
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.
Upvotes: 1
Reputation: 146
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;
Upvotes: 0
Reputation: 784
$config['sess_save_path']
in config file.Upvotes: 0
Reputation: 2499
Sharing a solution that helped me, try set your config variable like:
$config['sess_save_path'] = sys_get_temp_dir();
Upvotes: 222
Reputation: 146
In config.php sess_save_path
should be sys_get_temp_dir();
then it will resolve the error of mkdir(): Invalid path
Upvotes: 12
Reputation: 22532
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;
Upvotes: 6