Welcome Guest, Not a member yet? Register   Sign In
Extending an existing web application using Codeigniter4
#1

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
Reply
#2

CodeIgniter impliments it's own Session Handler.

But they should both work the same.

What don't you get about CodeIgniter Sessions?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
Reply
#4

Read the Session class:
https://github.com/codeigniter4/CodeIgni...n.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.
Reply
#5

(02-17-2024, 05:15 AM)kenjis Wrote: Read the Session class:
https://github.com/codeigniter4/CodeIgni...n.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.
Reply
#6

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.
Reply
#7

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
Reply
#8

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB