PHP output buffering

Simple question:

If I turn on output buffering ...

ob_start();
  $a = true;
  header('Location: page.php'); 
  $a = false;
ob_end_flush();

... will register as $ a as false, or simply redirect the page without processing the command (as if output buffering were not enabled)?

Thank!

+3
source share
3 answers

If you do not call exit()or die()after the header is redirected, $ a will be false, since the rest of the page continues to parse (with or without buffering).

If you have a special reason, header("Location: ...");always follows one of the above functions so as not to waste processor cycles or memory.

+8
source

, , . , . $a false . .

+2

It redirects to page.php without * processing the rest of the commands.

* Technically, execution continues after the header is called, unless you specifically stop it after (die, exit). You will never notice this if you just set variables and display stuff, but if you have commands that change the database, it can be very difficult to figure out where these changes come from.

+1
source

Source: https://habr.com/ru/post/1726618/


All Articles