codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.37k stars 1.9k forks source link

problem: #3686

Closed Muneeb1998 closed 4 years ago

Muneeb1998 commented 4 years ago

i face error when i deploy CodeIgniter 4 project on hosting CRITICAL - 2020-09-26 07:18:24 --> ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'ini_set(): Head...', '/home/p...', 43, Array)

1 /home/mlnacta/public_html/habib_site/app/Controllers/BaseController.php(43): ini_set('session.save_pa...', '')

2 /home/mlnacta/public_html/habib_site/vendor/codeigniter4/framework/system/CodeIgniter.php(891): App\Controllers\BaseController->initController(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), Object(CodeIgniter\Log\Logger))

3 /home/mlnacta/public_html/habib_site/vendor/codeigniter4/framework/system/CodeIgniter.php(399): CodeIgniter\CodeIgniter->createController()

4 /home/mlnacta/public_html/habib_site/vendor/codeigniter4/framework/system/CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)

5 /home/mlnacta/public_html/habib_site/index.php(44): CodeIgniter\CodeIgniter->run()

6 {main}

CRITICAL - 2020-09-26 07:18:24 --> Uncaught ErrorException: Cannot modify header information - headers already sent by (output started at /home/mlnacta/public_html/habib_site/app/Config/Events.php:27) in /home/mlnacta/public_html/habib_site/vendor/codeigniter4/framework/system/Debug/Exceptions.php:164 Stack trace:

0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', '/home/p...', 164, Array)

1 /home/mlnacta/public_html/habib_site/vendor/codeigniter4/framework/system/Debug/Exceptions.php(164): header('HTTP/1.1 500 In...', true, 500)

2 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException))

3 {main}

thrown

0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()

1 {main}

michalsn commented 4 years ago
  1. What CodeIgniter version are you using?
  2. Can you check if you have a line if (ini_get('zlib.output_compression')) in your app/Config/Events.php file?
Muneeb1998 commented 4 years ago
  1. What CodeIgniter version are you using?
  2. Can you check if you have a line if (ini_get('zlib.output_compression')) in your app/Config/Events.php file?
  1. i am using 4.0.4 version
  2. no
paulbalandan commented 4 years ago

It seems your code in BaseController is throwing errors when setting the session path. Can you paste the contents of your BaseController?

Muneeb1998 commented 4 years ago

`<?php namespace App\Controllers;

/**

use CodeIgniter\Controller; // JAK Cutom: use App\Libraries\App; // JAK Cutom;

class BaseController extends Controller {

/**
 * An array of helpers to be loaded automatically upon
 * class instantiation. These helpers will be available
 * to all other controllers that extend BaseController.
 *
 * @var array
 */
protected $helpers = [];

/**
 * Constructor.
 */
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
    // Do Not Edit This Line
    parent::initController($request, $response, $logger);

    //--------------------------------------------------------------------
    // Preload any models, libraries, etc, here.
    //--------------------------------------------------------------------
    // E.g.:.
    $this->session  = \Config\Services::session();
    if(isset($_GET['lang'])){
        $this->session->set(array(
            'lang' => $_GET['lang']
        ));
    }
    // else{
    //  $this->session->set(array(
    //      'lang' => 'English'
    //  ));
    // }
    // print_r($_SESSION['lang']);
    // $r = (explode('/', uri_string(), 2));
    // JAK Cutom:
    $this->libraryApp   = new App($this);
    helper('front');
    // JAK Cutom;
}

} `

enix-app commented 4 years ago

I guess these line:

$this->libraryApp = new App($this);
helper('front');

I don't know what's in it.

michalsn commented 4 years ago

From your answer I see you upgraded to 4.0.4 from lower version, so you don't have a check against zlib.output_compression in place.

It's either the wrong sessionSavePath or enabled zlib.output_compression extension.

I will close this since the problem occurs only on your production server, but if none of the suggestions solve the problem, please feel free to continue the conversation.