CodeIgniter Forums
Extending an existing web application using Codeigniter4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Extending an existing web application using Codeigniter4 (/showthread.php?tid=90150)



Extending an existing web application using Codeigniter4 - r24in - 02-16-2024

Hi, 

I have an existing web application written in php. I want to develop a new module for the application using Codeigniter 4.

The problem is with sessions - the native php session (sess_...) and Codeigniter's session seems different to me. I have no clue what I am missing. Please help.

Thanks


RE: Extending an existing web application using Codeigniter4 - InsiteFX - 02-16-2024

CodeIgniter impliments it's own Session Handler.

But they should both work the same.

What don't you get about CodeIgniter Sessions?


RE: Extending an existing web application using Codeigniter4 - r24in - 02-17-2024

The problem is I can't get the session variables set by the current application eg $_SESSION["username"] is a session variable in the application. In the Codeigniter4 module I don't get this session variable. I also see that Codeigniter4 is creating a seperate session file.


RE: Extending an existing web application using Codeigniter4 - kenjis - 02-17-2024

Read the Session class:
https://github.com/codeigniter4/CodeIgniter4/blob/342dd3afab621a2c4b835d4bafb3da4642eaa5e2/system/Session/Session.php#L280

Both use PHP session, but the configuration is different.
You need to use the same configuration.
Or use CI Session in both, 
or use native PHP session in both.


RE: Extending an existing web application using Codeigniter4 - r24in - 02-17-2024

(02-17-2024, 05:15 AM)kenjis Wrote: Read the Session class:
https://github.com/codeigniter4/CodeIgniter4/blob/342dd3afab621a2c4b835d4bafb3da4642eaa5e2/system/Session/Session.php#L280

Both use PHP session, but the configuration is different.
You need to use the same configuration.
Or use CI Session in both, 
or use native PHP session in both.

Thanks for the reply.

Is there a Config file where I can set this up? I think we should avoid making edits to system files.


RE: Extending an existing web application using Codeigniter4 - r24in - 02-17-2024

I need to work with the native php session since the existing application might break if I switch to Codeigniter session. 

I tried looking into config files to see if CI session can be disabled. I did not find any config parameter. After trying to work along the error message, I was able to load the welcome page by commenting out the following lines in system/Common.php lines 981 to 989 like so:

function session(?string $val = null)
    {  /*
        $session = Services:Confusedession();

        // Returning a single item?
        if (is_string($val)) {
            return $session->get($val);
        }

        return $session; */
        return true;
    }

It works but I am not sure if its the right thing to do.


RE: Extending an existing web application using Codeigniter4 - kenjis - 02-17-2024

There is no config to disable Session in CI4. Because it is used when it is needed.
So basically, if you don't use CI4 Session, it does not work.

I don't know this is good for you, but we can use CI4 session in plain PHP if there is no conflicts.
https://github.com/kenjis/ci4-session-in-plain-php


RE: Extending an existing web application using Codeigniter4 - r24in - 02-17-2024

(02-17-2024, 07:43 PM)kenjis Wrote: There is no config to disable Session in CI4. Because it is used when it is needed.
So basically, if you don't use CI4 Session, it does not work.

I don't know this is good for you, but we can use CI4 session in plain PHP if there is no conflicts.
https://github.com/kenjis/ci4-session-in-plain-php

Thanks. This appears to be a better solution.