3

I'm using CI 3.1.10.In the index.php file i use development enviroment.

MY controller

<?php
class Test extends CI_Controller {
public function index(){
    echo CI_VERSION; 
 }
}

?>

When i try to access the test class then it show me this error

This is the image that show me the warning.

Screenshot of the error is attached

Danish Danish
  • 43
  • 1
  • 1
  • 2

9 Answers9

7
ob_start();

on the first line of index.php in root directory. This works.

Vikas bhatiya
  • 71
  • 1
  • 4
4

For me the error occured because i accidentally added some empty lines after php closing bracket ?> in a helper class i loaded before loading the session library.

Sam Tigle
  • 393
  • 3
  • 14
1

For further understanding why this happens, php is supposed to set headers before it can send the response body to either browser or console.

Usual suspects are print_r, print, echo or whitespaces before modifying headers using methods like header, session_start, set_cookie etc.

This is answered nicely here as well How to fix "Headers already sent" error in PHP

f_i
  • 3,084
  • 28
  • 31
1

In my case, the empty line at the beginning of the file, before <? php".

LatVIK
  • 11
  • 1
  • 1
    Please be more clear, he/she should do what with the line, delete it or what. thanks for helping out – user2682025 Dec 01 '21 at 18:52
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 02 '21 at 08:02
0

Remove Close tag from the Controller ?> then check

Boominathan Elango
  • 1,156
  • 2
  • 7
  • 20
0

Open the config.php and add ob_start(); it will help to delay the sending of the HTTP header

Look at the example below

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
ob_start();
Tobiloba
  • 1,618
  • 1
  • 11
  • 7
0

About codeignitor. It is about case sensitivity. My file name was Header.php after changing it to header.php. it worked for me.

0

In my case using delight/auth I had the same error when calling my login.php.

The problem was that the require 'vendor/autoload.php'; was NOT the FIRST statement in the file.

Put it first and all worked fine. In ALL my .php that use this service <? php require 'vendor/autoload.php'; include ('root.php'); include($root."db_settings.php"); require_once 'errormsg.php';

Good luck

0

on index.php file at the top paste this

ob_start(); 

this works for me

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Asif
  • 1
  • 1