CodeIgniter Forums
maybe need to modify session garbage collector section. - 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: maybe need to modify session garbage collector section. (/showthread.php?tid=72244)



maybe need to modify session garbage collector section. - eterv - 11-26-2018

I think that maybe need to modify session garbage collector section.

Session/Handlers/FileHandler.php
public function gc();

original code is ...

$pattern = sprintf(
  '/^%s[0-9a-f]{%d}$/', preg_quote($this->cookieName, '/'), ($this->matchIP === true ? 72 : 40)
);


but, why 40? I can't understand this.

for example, one of my session file name is a_sessionba2o0ekqqv8ogvqonrl2u0uqg86so8fm
a_session is cookiename.
so, session id is "ba2o0ekqqv8ogvqonrl2u0uqg86so8fm". the length of this string is 32.

So, actually, in my case 32 is correct value.
and I found this code part.

in Session/Session.php
protected function configureSidLength();

after be called this function, sidRegexp value is, "[0-9a-v]{32}" (in my case)

So, I tried to modify gc part code.

Here are some code.

PHP Code:
       $sid_regexp '';
 
       $bits_per_character = (int) (ini_get('session.sid_bits_per_character') !== false ini_get('session.sid_bits_per_character') : 4);
 
       $sid_length = (int) (ini_get('session.sid_length') !== false ini_get('session.sid_length') : 40);
 
       switch ($bits_per_character) {
 
           case 4$sid_regexp '[0-9a-f]'; break;
 
           case 5$sid_regexp '[0-9a-v]'; break;
 
           case 6$sid_regexp '[0-9a-zA-Z,-]'; break;
 
       }
 
       $sid_regexp .= '{' $sid_length '}';
 
       $pattern sprintf'/^%s%s$/'preg_quote($this->cookieName'/'), $sid_regexp );

 
       /* // Original Code
        $pattern = sprintf(
                '/^%s[0-9a-f]{%d}$/', preg_quote($this->cookieName, '/'), ($this->matchIP === true ? 72 : 40)
    );*/ 


After modify it, Finally My php Garbage Collector removed garbage session files.

So, please modify this part properly.