cannot modify header information

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
heapcoll
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 12, 2019 12:49 pm

Tue Nov 12, 2019 1:07 pm

I am very new to php, and my boss has asked me to get an old application updated and running in php 7. I have run into a lot of issues, but this one has me stumped.

I am getting this error
E_WARNING Error in file �lib.php� at line 475: Cannot modify header information - headers already sent by (output started at /Users/collin/code/cls_threesixty/lib/locale.php:2)

lines 2 - 4 of locale are as follows
echo '<pre>';
print_r(debug_backtrace());
echo '<pre>';

lines 473 - 476 contain this function
function my_header($location)
{
header(addSID($location));
}

the first time header is even used is within that function, so how can header already have been sent?
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 864
Joined: Mon Feb 22, 2016 5:52 pm

Tue Nov 12, 2019 2:20 pm

If you use print, echo, var_dump or print_r you have sent the header.

If you have things like this:

Code: Select all

echo '<pre>';
print_r(debug_backtrace());
echo '<pre>';
in your code, you may well have big problems as it might reveal information you need to keep to yourself.
heapcoll
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 12, 2019 12:49 pm

Tue Nov 12, 2019 2:31 pm

Thank you Hyper
I have so much to learn with PHP still. I didn't realize that those things sent headers.
I commented out the echo and it resolved my issue
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 864
Joined: Mon Feb 22, 2016 5:52 pm

Wed Nov 13, 2019 9:39 am

I commented out the echo and it resolved my issue
This would be better deleted:

Code: Select all

echo '<pre>';
print_r(debug_backtrace());
echo '<pre>';
As stated, these things can reveal information which may allow access to your server, especially if you are running a version of PHP before V 7.
Post Reply