Ehsan
Ehsan

Reputation: 2285

How can I delete all of header that previous sent

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.

Upvotes: 1

Views: 276

Answers (2)

Fabian Schmengler
Fabian Schmengler

Reputation: 24551

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)

Upvotes: 2

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

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

Upvotes: 2

Related Questions