session error in codeigniter?

2019-01-31 12:54发布

问题:

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);

回答1:

Sharing a solution that helped me, try set your config variable like:

$config['sess_save_path'] = sys_get_temp_dir();


回答2:

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`)
);


回答3:

In config.php sess_save_path should be sys_get_temp_dir(); then it will resolve the error of mkdir(): Invalid path



回答4:

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;


回答5:

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.



回答6:

Try this in your config.php $config['sess_save_path'] = NULL



回答7:

  1. Use absolute path for $config['sess_save_path'] in config file.
  2. Point it to your writable temporary directory.
  3. Make sure the directory is under the directory allowed in apache or nginx config.


回答8:

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;