1

In PHP a common error is (Header already sent) and it's reason is an space and error detection in this case is difficult. Is there any code to delete all of header that previous sent? If exist a code or function it would be very very usefull.

Ehsan
  • 2,273
  • 8
  • 36
  • 70

2 Answers2

2

No. What is sent cannot be "un-send". Fix your code to not trigger unintended header flush (the simplest approach we be stop using "?>" at the end of scripts). Also you can enable output buffering: http://php.net/manual/en/book.outcontrol.php

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
2

No. "Sent" means "sent to the client". You cannot tell those TCP packages to come back once they leave your server.

Follow the IPO principle (Input-Processing-Output) and you will not have these problems.

This means, the flow of your PHP code should always be like:

  1. fetch input from request variables
  2. process input, fetch external data
  3. create the HTTP response (create headers, then echo output)
Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111