0

I used header redirect between ob_start and ob_clean, but it still redirected.

I just want to know why ob_clean() doesn't work.Thank you!

ob_start();
header("location:../index.html");
ob_clean()
ob_end()
ADyson
  • 57,178
  • 14
  • 51
  • 63

1 Answers1

1

This is because output buffering doesn't affect headers.

The manual for ob_start says:

While output buffering is active no output is sent from the script (other than headers)

(my bold).

Therefore ob_clean() doesn't remove the header which you created.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Sure it affects headers ;) Haven't you tried this? https://github.com/php/php-src/issues/7953 – tim Jan 17 '22 at 04:05
  • @Tim it sounds like it's probably ob_gzhandler which affects the header in your scenario, not the core output buffering functionality. Have you checked what headers the browser actually receives in that particular case? I haven't used it but per https://www.php.net/manual/en/function.ob-gzhandler.php it sounds like it might alter the content-encoding header specifically – ADyson Jan 17 '22 at 07:28
  • Yes I checked the headers. It seems the bug was confirmed being a problem with ob_gzhandler. This went a bit off topic so I will end it there. Thanks for the reply. :) – tim Jan 20 '22 at 00:08