Cannot modify header information - headers already sent by


#1

hello,

I need assistant to resolve this issue. I opened my website and I don’t understand why it does not reload like it suppose to. I have never change any code prior to this issue occurs. it should be load into form that I set as a header statement. But, once I open my site, this trouble occurs like this
"Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd2/136/1455136/public_html/header.php:4) in /storage/ssd2/136/1455136/public_html/index.php on line 16"

anyway this is my website http://bitcoincrypto.comule.com

thanks for the attention


#2

Hi @alfarica!

Please append the following code to a new line in .htaccess:

php_value output_buffering on

#3

I added this code and nothing happened.

Please advise on what else I could do.


#4

Above code must solve your problem

  • Make sure the file name is .htaccess (mind the dot)
  • Make sure .htaccess file is in your public_html folder.
  • Make sure your code is correct.

Explanation

Once you output any kind of string with echo or pront functions apache server sends the response to the client with http headers. So, all the response headers are sent when you echo the first string. You can’t use header function after this process. You can use above code to use output buffering technique which means the output is not sent until full script is executed. Some other fixes are… add header function to the top of your php script, don’t add any empty rule before <?php tag.

If you call header after html code, the best fix is mentioned above by @teodor


#5

I have changed everything as per your advice still no luck.

It works perfectly on my local server.


#6

Please clear your browser cache and try again.


If the problem is still not solved you will need to use ob_start() and ob_end_flush() in order to solve this issue:

<?php

ob_start();

[...php code...]

header([...]);

ob_end_flush();

[...php code...]

?>

#7

Hi Teodor,

This worked :slight_smile: thank you.

But do remember to put ob_start(); at the start of your script. No need to close it.


#8

We are glad you solved it out! :blush:


#9