0

A PHP script contains some output, that causes

Warning: Cannot modify header information - headers already sent (output started at script:line)

when we later try to send a redirect header - but only on the live server.

On the local server the output appears as well, but the redirect still works.

So it seems there is a setup difference between the two servers (in ini.php / .htaccess / via ini_set ?) What setting could cause this difference?

Update:

To make this clear: I do not want to suppress this error, quite the opposite: I want the redirect to not work on my local server as well.

Alexander Presber
  • 6,429
  • 2
  • 37
  • 66
  • 1
    You can't "suppress" this error (I don't recommend suppressing _any_ errors), you just can't modify headers after they have already been sent. – GrumpyCrouton Jan 23 '19 at 17:36
  • Don't suppress or ignore these warnings. You can't send headers after you've sent part of the body. You may want to look at how HTTP requests/responses work to understand why this is. – Devon Bessemer Jan 23 '19 at 17:38
  • @GrumpyCrouton The text output happens on both servers (I see it locally when I put in an `exit()` statement, but the redirect works locally nonetheless. Why could that be? – Alexander Presber Jan 23 '19 at 17:38
  • @AlexanderPresber Don't know, but it would be best to not send headers after you've sent part of the body regardless of if it works or not, because it's not supposed to work. – GrumpyCrouton Jan 23 '19 at 17:44
  • @GrumpyCrouton I totally get it, it’s just that my test suite runs fine locally and does not see the underlying problem, because this error is somehow not triggered. I want it to be. – Alexander Presber Jan 23 '19 at 17:46
  • @AlexanderPresber Yeah unfortunately I have no idea why this would work on your local server :/ – GrumpyCrouton Jan 23 '19 at 17:47
  • 1
    @AlexanderPresber The rather comprehensive answer on the duplicate target features sections about what in the php.ini effects on that. Can you make sure to take the time to read it, ans possibly reedit this question afterwards if the points mentioned over there do not work? – Félix Adriyel Gagnon-Grenier Jan 23 '19 at 19:22
  • Thanks @FélixGagnon-Grenier. I now found out that the answer to this question is that `php_value output_buffering 'on'` can cause this phenomenon. I vote for re-opening the question because it is explicitly **not** about *fixing* the error but about how to make sure the *error shows up* in the first place. – Alexander Presber Jan 25 '19 at 14:59

0 Answers0