Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session error in codeigniter?

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);
like image 783
bikram kc Avatar asked Jun 25 '15 06:06

bikram kc


People also ask

What is session in CodeIgniter?

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.

How check session is set in CodeIgniter?

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.

How can use session variable in CodeIgniter?

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.

Are session data that will only be available for the next request and is then automatically cleared?

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”).


3 Answers

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

$config['sess_save_path'] = sys_get_temp_dir();
like image 176
Wellyngton Avatar answered Oct 18 '22 00:10

Wellyngton


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`)
);
like image 26
Md. Khairul Hasan Avatar answered Oct 18 '22 00:10

Md. Khairul Hasan


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

like image 12
Md Rashadul Islam Avatar answered Oct 18 '22 01:10

Md Rashadul Islam