Click to See Complete Forum and Search --> : handling PHP errors in a new browser window


jasongr
08-11-2004, 04:34 AM
Hello

I have written my own PHP code for handling errors and I have used set_error_handler to configure PHP to work with it.
Everything works fine. When I get an error, my code is invoked.

Here is my problem:
I would like to display informaion about the error in a NEW browser window and not in the same window that the error occured in (the error could poternitally be in an inner frame, and IFrame).
The problem is that the code that handles the error is on the Server side (PHP). I need to get to the client side in order to open a new browser window.

I tried doing the following trick.
When I encounter a bug in my PHP error handling function, I store state information about the bug, including the fact that a bug has occurred.
The I thought that I would let the page continue rendering itself (behaving as if the error never occurred), and on the onload event of the page, I would check if an error has occurred. If so, I would open a new browser window and send to it all the state informaion about the error that I have stored.
The problem with this solution is that PHP doesn't continue rendering the page once it encounters an error, and obviously that doesn't cause my onload code to be rendered.

Is there some way I can cause my error handling function to display information about the bug in a new browser window?

regards
Jason

AdamGundry
08-11-2004, 07:04 AM
Rather than checking from onload whether an error has occurred, your error handling code could output a single Javascript instruction (to open a new window) in <script> tags, then exit. While the result might not be perfectly formed XML, as long as the error does not occur under unusual circumstances the code should get executed. For example:

function errorHandler($errno, $errstr, $errfile, $errline){
$url = "errorInfo.php?no=$errno&str=$errstr&file=$errfile&line=$errline";

echo "<script type=\"text/javascript\">\nwindow.open('$url');\n </script>\n";
echo '<noscript><p>An error has occurred, please follow <a href="$url">this link</a> for more information.</p></noscript>';
exit();
}


Adam

jasongr
08-11-2004, 07:06 AM
I would like to use such solution but to send more information to the new window. The problem is that there is a limit on the length of the URL parameter (not more than 255 characters).
Is there a way of sending the information to the page in another fashion?

AdamGundry
08-11-2004, 07:13 AM
If your data won't fit in a GET request, the you could use POST. That would require you to construct a form dynamically in the error handling function and submit it automatically via Javascript. Alternatively, you could store the error data on the server side (e.g. in a temporary or session file) and simply pass a session ID on the URL.

Adam