Welcome Guest, Not a member yet? Register   Sign In
Set up but...
#1

I came across a error message below, using CodeIgniter 3.0.0.

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/application/controllers/Pages.php:20)

Filename: core/Common.php

Line Number: 569

Backtrace:

File: /Applications/MAMP/htdocs/application/controllers/Pages.php
Line: 8
Function: show_404

File: /Applications/MAMP/htdocs/index.php
Line: 294
Function: require_once

Line 569 of The Common.php is
function set_status_header($code = 200, $text = '')
{
if (is_cli())
{
return;
}

if (empty($code) OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}

if (empty($text))
{
is_int($code) OR $code = (int) $code;
$stati = array(
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',

300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',

400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',

500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);

if (isset($stati[$code]))
{
$text = $stati[$code];
}
else
{
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
}

if (strpos(PHP_SAPI, 'cgi') === 0)
{
header('Status: '.$code.' '.$text, TRUE);
}
else
{
$server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
}
}
}  

What should I do?
Reply
#2

(05-26-2015, 04:51 PM)Jeremy Wrote: I came across a error message below, using CodeIgniter 3.0.0.

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/application/controllers/Pages.php:20)

Filename: core/Common.php

Line Number: 569

Backtrace:

File: /Applications/MAMP/htdocs/application/controllers/Pages.php
Line: 8
Function: show_404

File: /Applications/MAMP/htdocs/index.php
Line: 294
Function: require_once

Line 569 of The Common.php is
function set_status_header($code = 200, $text = '')
{
if (is_cli())
{
return;
}

if (empty($code) OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}

if (empty($text))
{
is_int($code) OR $code = (int) $code;
$stati = array(
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',

300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',

400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',

500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);

if (isset($stati[$code]))
{
$text = $stati[$code];
}
else
{
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
}

if (strpos(PHP_SAPI, 'cgi') === 0)
{
header('Status: '.$code.' '.$text, TRUE);
}
else
{
$server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
}
}
}  

What should I do?
Edit filename: core/Common.php, line number: 257

Before
Code:
return $_config[0] =& $config;

After
Code:
$_config[0] =& $config;
return $_config[0];
Reply
#3

Post your pages controller. Did you output something before calling show_404?
Reply
#4

First off - don't modify core/Common.php. Never a good idea to modify core files, especially when this has nothing to do with that.

Look at the error message: "Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/application/controllers/Pages.php:20)" That tells you approximately where the output happened.

But to understand what's going on - some part of your code output something (even a space would do it) before CodeIgniter sent the headers to the browser. This error would show up in a number of common situations, like:

- space (or other characters) before the opening PHP tag in a PHP file (easy to accidentally do if you forgot to switch to the console before you started typing. Yeah, that's from experience. Smile
- you echo something out, do a var_dump, print_r, etc for debugging.

So start looking around line 20 of your Pages controller for something that may be spitting out text.
Reply
#5

(05-27-2015, 06:10 AM)eboominathan Wrote:
(05-26-2015, 04:51 PM)Jeremy Wrote: I came across a error message below, using CodeIgniter 3.0.0.

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/application/controllers/Pages.php:20)

Filename: core/Common.php

Line Number: 569

Backtrace:

File: /Applications/MAMP/htdocs/application/controllers/Pages.php
Line: 8
Function: show_404

File: /Applications/MAMP/htdocs/index.php
Line: 294
Function: require_once

Line 569 of The Common.php is
function set_status_header($code = 200, $text = '')
{
if (is_cli())
{
return;
}

if (empty($code) OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}

if (empty($text))
{
is_int($code) OR $code = (int) $code;
$stati = array(
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',

300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',

400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',

500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);

if (isset($stati[$code]))
{
$text = $stati[$code];
}
else
{
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
}

if (strpos(PHP_SAPI, 'cgi') === 0)
{
header('Status: '.$code.' '.$text, TRUE);
}
else
{
$server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
}
}
}  

What should I do?
Edit filename: core/Common.php, line number: 257

Before

Code:
return $_config[0] =& $config;

After

Code:
$_config[0] =& $config;
return $_config[0];
Thanks, I got it.
Reply
#6

(05-27-2015, 06:51 AM)CroNiX Wrote: Post your pages controller. Did you output something before calling show_404?

Thanks, I got it.
Reply
#7

(05-27-2015, 07:11 AM)kilishan Wrote: First off - don't modify core/Common.php. Never a good idea to modify core files, especially when this has nothing to do with that.

Look at the error message: "Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/application/controllers/Pages.php:20)" That tells you approximately where the output happened.

But to understand what's going on - some part of your code output something (even a space would do it) before CodeIgniter sent the headers to the browser. This error would show up in a number of common situations, like:

- space (or other characters) before the opening PHP tag in a PHP file (easy to accidentally do if you forgot to switch to the console before you started typing. Yeah, that's from experience. Smile
- you echo something out, do a var_dump, print_r, etc for debugging.

So start looking around line 20 of your Pages controller for something that may be spitting out text.

Thanks, I got it.
Reply
#8

very Good Coding Technique.. Useful Ideas Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB