bikram kc bikram kc - 4 months ago 36
PHP Question

when i want to use session in codeigniter it says error. why?

when I want to load session library i says error like:
what would be the solution please help me.

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 full code
the controller login that loads loginview.php
controller
login.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

function __construct()
{
parent::__construct();
}

function index()
{
$this->load->helper(array('form'));
$this->load->view('login_view');
}

}

?>


view
the login view is the form that post username and password to the controller verifylogin.php

loginview.php

<?php echo form_open('verifylogin'); ?>
<label for="username">Username:</label>
<input type="text" size="20" id="username" name="username"/>
<br/><br>
<label for="password">Password:</label>
<input type="password" size="20" id="passowrd" name="password"/>
<br/><br>
<input type="submit" value="Login"/>
<input type="reset" value="Reset"/>
<p class="text-success"><?php echo validation_errors(); ?></p>
</form>


controller
the verifylogin controller verifies the login username and password with the username and password saved in database table 'users' through the model user.php
verifylogon.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLogin extends CI_Controller {

function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}

function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');

$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view('login_view');

}
else
{
//Go to private area
redirect('home', 'refresh');
}

}

function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');

//query the database
$result = $this->user->login($username, $password);

if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'username' => $row->username
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
}
?>


and model
this model get id, username and password from database table
user.php

<?php
Class User extends CI_Model
{
function login($username, $password)
{
$this -> db -> select('id, username, password');
$this -> db -> from('users');
$this -> db -> where('username', $username);
$this -> db -> where('password', MD5($password));
$this -> db -> limit(1);

$query = $this -> db -> get();

if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}
?>

Answer

Have you solved your problem already? I know thats an old post, just sharing a solution that helped me. Try set your config variable like:

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