CodeIgniter Forums
Problem with session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Problem with session (/showthread.php?tid=75928)



Problem with session - Codinglander - 03-30-2020

Hi there again Smile

I want to access session in all controllers by using BaseController.

First time to access a site it works fine, also when I navigate everytime to another site (e.g.: first I navigate to "domain.com/users", then to "domain.com/users/login").

But if I reload one site there will be an error like this:

Quote:[b]Fatal error[/b]: Uncaught ErrorException: touch(): Unable to create file NULL/ci_sessionbsfep1vfs4hk2m2ndm26dlittj089hnp because No such file or directory in C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php:252 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'touch(): Unable...', 'C:\\xampp\\htdocs...', 252, Array) #1 C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php(252): touch('NULL/ci_session...') #2 [internal function]: CodeIgniter\Session\Handlers\FileHandler->write('bsfep1vfs4hk2m2...', '__ci_last_regen...') #3 [internal function]: session_write_close() #4 {main} thrown in [b]C:\xampp\htdocs\kighlander.local\system\Session\Handlers\FileHandler.php[/b] on line [b]252[/b]


Also in the public folder is generated a directory named "NULL".
In it are generated files like:

Quote:ci_sessionbsfep1vfs4hk2m2ndm26dlittj089hnp


What is the reason of these effects ?

Is there a solution?

Thanks,
Kighlander Wink

Update: my controllers:

BaseController:
PHP Code:
<?php
namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
Config\Services;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = [
           
'form',
    ];

    /**
     * @var string
     * Holds the session instance
     */
    protected $session;


    /**
     * @var array
     * Passes default settings for displaying in views
     */
    public $data = [
        'title' => 'defaultTitle',
    ];

    /**
     * Constructor.
     */
    public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        //--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();

        if(session_status() == PHP_SESSION_NONE)
        {
            $this->session Services::session();
        }
    }



my users controller:

PHP Code:
<?php
/**
 * Created by PhpStorm.
 * User: Kighl
 * Date: 29.03.2020
 * Time: 14:01
 */

namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
Users extends BaseController
{
    public function index()
    {
        //$this->data['title'] = 'my new title';
        echo view('users/profile'$this->data);
    }

    public function login()
    {
        echo view('users/login'$this->data);
    }




RE: Problem with session - dave friend - 03-30-2020

What is the value assigned to [i]$sessionSavePath[/i] in the file C:\xampp\htdocs\kighlander.local\app\Config\app.php?


RE: Problem with session - Codinglander - 03-30-2020

My session-variables are:
PHP Code:
public $sessionDriver            'CodeIgniter\Session\Handlers\FileHandler';
public 
$sessionCookieName        'ci_session';
public 
$sessionExpiration        7200;
public 
$sessionSavePath          WRITEPATH 'session';
public 
$sessionMatchIP           false;
public 
$sessionTimeToUpdate      300;
public 
$sessionRegenerateDestroy false

is this helpful?


RE: Problem with session - Codinglander - 03-30-2020

Oh, I've found the reason... After asking me the session-path I checked ALL my configuration files. And after that I store all my configuration in app/config. Before that I had a mix of that with the .env-file...
Now my app running fine.

Thanks !!!


RE: Problem with session - ivan1900 - 03-31-2020

I have a same iusse before update from rc 2 to final 4.0.2.

I solve it uncoment line in BaseController to getup session service.


RE: Problem with session - savhascelik - 09-06-2021

If you are using the .env file, you should make an adjustment as follows. Otherwise, it continues to create a NULL folder.


app.sessionSavePath = '/writable/session' #path add