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);
Sharing a solution that helped me, try set your config variable like:
$config['sess_save_path'] = sys_get_temp_dir();
Answer:
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`)
);
Answer:
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;
Answer:
In config.php sess_save_path
should be sys_get_temp_dir();
then it will resolve the error of mkdir(): Invalid path
Answer:
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.
Answer:
Try this in your config.php
$config['sess_save_path'] = NULL
Answer:
- Use absolute path for
$config['sess_save_path']
in config file. - Point it to your writable temporary directory.
- Make sure the directory is under the directory allowed in apache or nginx config.
Answer:
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;
Answer:
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'
Answer:
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;
Tags: codeigniter, phpphp, session