phpcodeigniterckfinder

CKFinder with Codeigniter 3 & PHP 7.3 - CheckAuthentication with PHP Session


I am in the process of upgrading some older Codeigniter 2.x websites to use php 7.3 and the latest version of Codeigniter (3.1.10), and have come across a bug with the CKFinder authentication no longer accepting the PHP native session that has worked in the past.

This previously worked:

$_SESSION['authorized'] = TRUE;

And then inside the CKFinder config

return isset($_SESSION['authorized']) && $_SESSION['authorized'];

However this longer recognizes the session. I have done some research and have found some other solutions that involve using CI's session library inside the CKFinder config, by loading in CI's index.php. e.g.

//test_session.php  (inside the root of CKFinders where config.php is stored)
ob_start();
define("REQUEST", "external");
$temp_system_path = $_SERVER["DOCUMENT_ROOT"].'/system';
$temp_application_folder = $_SERVER["DOCUMENT_ROOT"].'/application';
include($_SERVER["DOCUMENT_ROOT"].'/index.php');
ob_end_clean();
$CI =& get_instance();

if($CI->session->userdata('authorized') === TRUE) {
  return true;
}

  

This code works on its own in the test_sesion.php file, although i feel like it is a bit overkill, as I had to also made changes to the index.php to check for these temp paths, and update the default controller to ignore external requests. The problem is when I try to implement it inside the CKFinder config, it throws a bunch of PHP errors - particularly with how i am using HVMC with Codeigniter.

I found a very similar issues but the solution provided does not work, and the english is very bad

Call to a member function item() on null MX/Modules.php Line Number: 8 ckeditor and kcfinder

I am wondering if anyone has ever ran into this before or knows a way to bypass this and just use native php session as I did in the past.


Solution

  • I ended up resolving this by upgrading to the latest version of CKEditor & CKFinder, it may have better support for PHP 7.3 than the previous version I was using.

    Seems like on PHP 5.X with CI 2.X & older versions of CKFinder it is fine to just use the $_SESSION variable, but on newer versions of CI 3.X with PHP 7.X this more complicated solution is required.

    If using HMVC by wiredesignz like I am, then the other question that I referenced is helpful as it resolves another error when trying to implement this.