Let’s say that I want some generic error handling, which can be called from all over…
Ideally, I would like to just readirect to an error page using header('Location:... but, of course I can’t do that it if any output has been written, so …
1) how can I detect if any output has been written?
2) how can I load a new page if it has?
Perhaps I should buffer the entire page and only output it once I am certain that it is complete and no more errors can occur?
Use PHP’s built-in output buffering. At it’s simplest, all you need to do is call
ob_start()before anything that would produce output.There are other options you can take advantage of as well if you desire:
http://www.php.net/manual/en/function.ob-start.php