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);
The Session class permits you maintain a user's “state” and track their activity while they browse your site. CodeIgniter comes with a few session storage drivers: files (default; file-system based) database.
3 Answers. Show activity on this post. $this->session->set_userdata('some_name', 'some_value'); But before that ensure that you have the session library included.
Add Session Data The same thing can be done in CodeIgniter as shown below. $this->session->set_userdata('some_name', 'some_value'); set_userdata() function takes two arguments. The first argument, some_name, is the name of the session variable, under which, some_value will be stored.
Flashdata. CodeIgniter supports “flashdata”, or session data that will only be available for the next request, and is then automatically cleared. This can be very useful, especially for one-time informational, error or status messages (for example: “Record 2 deleted”).
Sharing a solution that helped me, try set your config variable like:
$config['sess_save_path'] = sys_get_temp_dir();
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`)
);
In config.php sess_save_path
should be sys_get_temp_dir();
then it will resolve the error of mkdir(): Invalid path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With