/    Sign up×
Community /Pin to ProfileBookmark

handling PHP errors in a new browser window

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryAug 11.2004 — 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:

[code=php]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();
}
[/code]


Adam
Copy linkTweet thisAlerts:
@jasongrauthorAug 11.2004 — 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?
Copy linkTweet thisAlerts:
@AdamGundryAug 11.2004 — 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
×

Success!

Help @jasongr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...