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.
Asked
Active
Viewed 248 times
1
-
4Write sensible PHP code in the first place to avoid this error. – Ed Heal Feb 12 '13 at 09:17
-
read this it explains this issue very well : http://stackoverflow.com/questions/8028957/headers-already-sent-by-php – Prasanth Bendra Feb 12 '13 at 09:18
-
3That would be like trying to change the address on a letter **after** putting it in the letterbox. – George Feb 12 '13 at 09:20
2 Answers
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:
- fetch input from request variables
- process input, fetch external data
- create the HTTP response (create headers, then echo output)

Fabian Schmengler
- 24,155
- 9
- 79
- 111