CodeIgniter Forums
Problem with session handling - 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 handling (/showthread.php?tid=90737)



Problem with session handling - Julesb - 04-25-2024

Hi
I've just upgraded to version 4.4.8
I have a session service of my own which I am using, however this now seems to clash with the codeigniter session service.
I get the following
ErrorException

ini_set(): A session is active. You cannot change the session module's ini settings at this time
SYSTEMPATH/Session/Handlers/FileHandler.php at line 72
Code:
65
66    public function __construct(SessionConfig $config, string $ipAddress)
67    {
68        parent::__construct($config, $ipAddress);
69
70        if (! empty($this->savePath)) {
71            $this->savePath = rtrim($this->savePath, '/\\');
72            ini_set('session.save_path', $this->savePath);
73        } else {
74            $sessionPath = rtrim(ini_get('session.save_path'), '/\\');
75
76            if ($sessionPath === '') {
77                $sessionPath = WRITEPATH . 'session';
78            }
79
I am not using the Codeigniter session service, it appears to being initialized by the method storePreviousURL in Codeigniter.php, the condition is purely


Code:
        if (isset($_SESSION)) {
            session()->set('_ci_previous_url', URI::createURIString(
                $uri->getScheme(),
                $uri->getAuthority(),
                $uri->getPath(),
                $uri->getQuery(),
                $uri->getFragment()
            ));
        }
Does anyone know of a way of fixing this easily?

Jules


RE: Problem with session handling - kenjis - 04-25-2024

1. Replace Session class with your Session class
2. Replace CodeIgniter class, and remove the if statement
See https://codeigniter4.github.io/CodeIgniter4/extending/core_classes.html#replacing-core-classes


RE: Problem with session handling - Julesb - 04-26-2024

Hi Kenjis

Thanks for the ideas

Had a long look at various solutions, replacing the session class was just a pain as it did not fix the problem and  caused others.

Ended editing Codeigniter.php

Line 1069 now reads
Code:
        if (isset($_SESSION)) {
            $_SESSION['_ci_previous_url'] = URI::createURIString(
                $uri->getScheme(),
                $uri->getAuthority(),
                $uri->getPath(),
                $uri->getQuery(),
                $uri->getFragment()
            );
        }


Basically as its a string returned by URI::createURIString you don't really need the complex session handling stuff, not an optimum solution though.

Managed to get my brain in gear, replaced the CodeIgniter class with my own.