• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to configure Session with Files

#1
Hello,
I try to use session_data with
PHP Code:
$config['sess_driver'] = 'files';// and 
$config['sess_save_path'] = 'cache_session'// with directory 'cache_session' with all the rights (chmod (777)). I try with cache_session/ and idem
$config['sess_expiration'] = 7200;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE
But, when i'm declaring a session variable and i try to use it in a page, i've this message :
"  touch(): Unable to create file cache_session\ci_session2f5e78f45e32a3fc8dadee822e0b8d68719d7e2a : failed to open stream: No such file or directory"
Error line number 234 in Sesssion_files_driver.php

At the first call of my controller named "Defaut", no problem for writing file for session and his name is (for example) : ci_session2f5e78f45e32a3fc8dadee822e0b8d68719d7e2a.
After, when i call my function (index) of the controller named "Debut" the view is loaded but an error appears.

I'm using session by database and all is all right and i wanted to try with files.

Can you help me please ? I do make a mistake somewhere

My Controller
PHP Code:
// i set my variable session in this controller for example. In the view associated, i can use the session variable. If i reload the page error appears
class Defaut extends CI_Controller
{
 
    private $vue 'vue1' ;
 
    public function __construct() { parent::__construct(); }
 
    
  public 
function index()
 {
      
// i defined a session variable named 'essai'
      
$this->session->set_userdata('essai''coucou') ;
      
$data['title'] = 'Titre' ;
      
$this->load->view($this->vue$data);
 }

My Other controller
PHP Code:
class Debut extends CI_Controller
{
 
    private $vue 'vue2' ;
 
    public function __construct() { parent::__construct(); }
 
    
     
public function index()
    {
 
      $this->load->view($this->vue);
     }

My other view name 'vue2'
PHP Code:
<?php echo 'value of var session :'.$this->session_userdata('essai') ; ?>
// error appears 
I resume : i call my first view with my first controller named "Defaut" who create my session variable and then, i call my second controller named "Debut". The view is loaded and when i try to see the contain of my session varaible named "essai", error appears.

Thanks for your help.
Reply

#2
(04-08-2015, 11:16 PM)casa Wrote: Hello,
I try to use session_data with

PHP Code:
$config['sess_driver'] = 'files';// and 
$config['sess_save_path'] = 'cache_session'// with directory 'cache_session' with all the rights (chmod (777)). I try with cache_session/ and idem
$config['sess_expiration'] = 7200;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE
But, when i'm declaring a session variable and i try to use it in a page, i've this message :
"  touch(): Unable to create file cache_session\ci_session2f5e78f45e32a3fc8dadee822e0b8d68719d7e2a : failed to open stream: No such file or directory"
Error line number 234 in Sesssion_files_driver.php

At the first call of my controller named "Defaut", no problem for writing file for session and his name is (for example) : ci_session2f5e78f45e32a3fc8dadee822e0b8d68719d7e2a.
After, when i call my function (index) of the controller named "Debut" the view is loaded but an error appears.

I'm using session by database and all is all right and i wanted to try with files.

Can you help me please ? I do make a mistake somewhere

My Controller

PHP Code:
// i set my variable session in this controller for example. In the view associated, i can use the session variable. If i reload the page error appears
class Defaut extends CI_Controller
{
 
    private $vue 'vue1' ;
 
    public function __construct() { parent::__construct(); }
 
    
  public 
function index()
 {
 
     // i defined a session variable named 'essai'
 
     $this->session->set_userdata('essai''coucou') ;
 
     $data['title'] = 'Titre' ;
 
     $this->load->view($this->vue$data);
 }

My Other controller

PHP Code:
class Debut extends CI_Controller
{
 
    private $vue 'vue2' ;
 
    public function __construct() { parent::__construct(); }
 
    
     
public function index()
 
   {
 
      $this->load->view($this->vue);
 
    }

My other view name 'vue2'

PHP Code:
<?php echo 'value of var session :'.$this->session_userdata('essai') ; ?>
// error appears 
I resume :  i call my first view with my first controller named "Defaut" who create my session variable and then, i call my second controller named "Debut". The view is loaded and when i try to see the contain of my session varaible named "essai", error appears.

Thanks for your help.
Hello, 
I had the exact problem, try to load the url  helper before you use the session library, this seems to help.

PHP Code:
$this->load->helper('url');
$this->load->library('session'); 
i hope this fix the problem.
Reply

#3
The comments in the config file include the solution to your problem:
PHP Code:
/*
...
| 'sess_save_path'
|
|    The location to save sessions to, driver dependent.
|
|    For the 'files' driver, it's a path to a writable directory.
|    WARNING: Only absolute paths are supported!
|
...
*/ 

Use an absolute path, not a relative path. In Linux, most absolute paths will start with / (in Windows, with a drive letter, like C:\). The easiest way to get an absolute path is to use something like APPPATH, BASEPATH, or FCPATH as the base of your path, or use PHP's realpath().
Reply

#4
@Offline mwhitney
Thanks a lot.. i had the config.php files of CI3.0 RC and this comments doesn't exists "WARNING: Only absolute paths are supported!".
That solve my problems Smile
Have a good day.
Reply

#5
(09-11-2015, 07:15 AM)mwhitney Wrote: The comments in the config file include the solution to your problem:
PHP Code:
sorry i'm new and i didn't understand what does it mean absolute path.

shall i change 
$config
['sess_save_path'] = NULL;

Thanks
/*
...
| 'sess_save_path'
|
|    The location to save sessions to, driver dependent.
|
|    For the 'files' driver, it's a path to a writable directory.
|    WARNING: Only absolute paths are supported!
|
...
*/ 

Use an absolute path, not a relative path. In Linux, most absolute paths will start with / (in Windows, with a drive letter, like C:\). The easiest way to get an absolute path is to use something like APPPATH, BASEPATH, or FCPATH as the base of your path, or use PHP's realpath().
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.