Reputation: 5533
I've noticed when a youtube page crashes it puts out a kind of encoded message which can be send to the developers of Youtube without the customers gaining knowledge about the Youtube infrastructure and used programms.
Is this idea a practice to do with your own sites?
Upvotes: 2
Views: 297
Reputation: 14931
Just thought of something like creating a custom error handler, with some basic encode/decode Function, it's up to you to extend the idea:
// Set error handler
set_error_handler("customError");
// The error function handler
function customError($error, $errorMessage, $errorFile, $errorLine){
echo(encodeError("<b>Error</b> [$error]: $errorMessage, on line $errorLine in $errorFile ."));
}
function encodeError($string){
$array = str_split($string,1);
$results = array();
foreach ($array as $value) {
$results[] = ord($value);
}
return(base64_encode(implode(".", $results)));
}
function decodeError($string){
$array = explode(".", base64_decode($string));
$results = array();
foreach ($array as $value) {
$results[] = chr($value);
}
return (implode("", $results));
}
// Trigger error
echo(3/0);
// We the developers decode it with the decode function
echo('<br><hr>'.decodeError('NjAuOTguNjIuNjkuMTE0LjExNC4xMTEuMTE0LjYwLjQ3Ljk4LjYyLjMyLjkxLjUwLjkzLjU4LjMyLjY4LjEwNS4xMTguMTA1LjExNS4xMDUuMTExLjExMC4zMi45OC4xMjEuMzIuMTIyLjEwMS4xMTQuMTExLjQ0LjMyLjExMS4xMTAuMzIuMTA4LjEwNS4xMTAuMTAxLjMyLjU2LjUzLjMyLjEwNS4xMTAuMzIuNjcuNTguOTIuMTE5Ljk3LjEwOS4xMTIuOTIuMTE5LjExOS4xMTkuOTIuMTAxLjEyMC4xMTIuMTA4LjQ4LjEwNS4xMTYuOTIuMTIyLjEwMS4xMTQuMTExLjQ5LjQ2LjExMi4xMDQuMTEyLjMyLjQ2'));
Upvotes: 0
Reputation: 157909
You don't need it with PHP.
Unlike Flash, PHP is running server-side. So, just make PHP to log whatever error messages.
Set these options in your php.ini file
log_errors = On
display_errors = Off
and you will need no volunteer users to see them
but only your web-server's error log to peek into
Upvotes: 2
Reputation: 6383
Most frameworks nowadays have the ability to use different application settings for production and development use.
In production mode (when the site is being used by customers) no errors should be visible, for security and design reasons. Therefore you often turn log_errors on, and display_errors off. When an unrecoverable error arises the user is presented with something like "Something went wrong, we're putting our best people on it right away." There is no point in showing the user some weird number, like "Error code 823." Use a cron worker to send you the error log, or just check the log manually, and make sure the error messages are verbose enough for you to track the bug down.
In development mode (when you're running the site locally during development) you probably want to see the errors as soon as they arise. Therefore you turn display_errors on. You probably won't mind if the design breaks, and hopefully you understand what's going on.
Error messages are a programmer's best friend, but your users should never have to experience them. If it happens, make sure to give the user some sensible feedback, and not just a blank page or a random error code.
Upvotes: 2