Help - Search - Members - Calendar
Full Version: Completely Clearing PHP Output
Invision Power Services > Community Forums > Community Web Design and Coding
.Jack
This is a question I've had for some time, and not been able to find the answer to...

Say I have an error handler, that prints out a friendly error message when an error occurs.... That is simple to do, BUT it will print that as soon as the error occurs throughout the script so the result is some of the page being printed and then the error HTML being printed within the page which looks odd..

What I would like is for the function to clear the page completely and THEN write the error HTML so I have a fresh blank page...

How can I do this?

Thanks in advance. original.gif
Danny
If all your PHP is before the HTML is printed, die(some_error_function($message)); cool.gif

Otherwise, I would take your HTML into PHP using heredoc and then if there is an error, just do die(unset($htmlvar).some_error_message($message));
.Jack
I dunno.. that's not really what I was after.. surely there must be some way to do it.. It must be done with the IPB error class.. no?
Danny
QUOTE(JCXP @ Jul 14 2005, 07:18 AM) *
I dunno.. that's not really what I was after.. surely there must be some way to do it.. It must be done with the IPB error class.. no?
Yes, but that doesn't clear the entire page. It is still the same wrapper etc, but the body is just the error. This might be what you're looking for: http://us2.php.net/set_error_handler
.Jack
I don't think you understand what I'm asking..
Michael_C
You could use output buffering...
.Jack
QUOTE(Michael_C @ Jul 14 2005, 02:56 PM) *
You could use output buffering...

That Had crossed my mind.. but that would require me to buffer the output from the very beginning and only dump at the very end.. I guess it's an option, but it seems kind of messy,, I don't really like the idea of holding the output right until the end of the script every time....
Rikki
It's different for IPB because it uses templates. It's not just echo'd out, it's inserted into a template so it's already in the right place.

If you want to clear any output, you will need to put your page output into a buffer so that it can be emptied if necessary without already having been sent.

http://uk2.php.net/manual/en/function.ob-start.php Should get you going original.gif
.Jack
QUOTE(Rikki @ Jul 14 2005, 02:58 PM) *
It's different for IPB because it uses templates. It's not just echo'd out, it's inserted into a template so it's already in the right place.

If you want to clear any output, you will need to put your page output into a buffer so that it can be emptied if necessary without already having been sent.

http://uk2.php.net/manual/en/function.ob-start.php Should get you going original.gif

OK.. Can you roughly explain to me about how the IPB template engine works in such a way that it allows the content to be printed the way it is? Thanks original.gif
Rikki
QUOTE(Jack Chapple @ Jul 14 2005, 03:01 PM) *
OK.. Can you roughly explain to me about how the IPB template engine works in such a way that it allows the content to be printed the way it is? Thanks original.gif


Well it loads templates, and if there's an error to be sent then it inserts that into the templates.

In effect, it's a custom method of output buffering. The templates are built as the script runs and it's only at the end that it is echo'd.
.Jack
QUOTE(Rikki @ Jul 14 2005, 03:04 PM) *
Well it loads templates, and if there's an error to be sent then it inserts that into the templates.

In effect, it's a custom method of output buffering. The templates are built as the script runs and it's only at the end that it is echo'd.

Gotcha... wink.gif

Thanks original.gif

Sometimes I have problems of thinking of ways to do things - but actually, once I can think of a way I don't have problems actually coding it... tongue.gif
Brendon Koz
If you don't want to go through all the trouble of that, you can always use a header() function call (with the Location parameter/property) and redirect it to a certain URL including a predefined query string that represents the error in question.

If you want ALL errors reported, you could still do it, but you'd have to be a bit more tricky in how you write/edit your error handling functions.

It's messier than using output buffering, but it can get the job done without altering a bunch of files. It's more of a temporary fix.
.Jack
QUOTE(malikyte @ Jul 14 2005, 03:11 PM) *
If you don't want to go through all the trouble of that, you can always use a header() function call (with the Location parameter/property) and redirect it to a certain URL including a predefined query string that represents the error in question.

If you want ALL errors reported, you could still do it, but you'd have to be a bit more tricky in how you write/edit your error handling functions.

It's messier than using output buffering, but it can get the job done without altering a bunch of files. It's more of a temporary fix.

That's a good idea too.. but the template idea is much neater original.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.