Is there a way to code error messages in PHP

I noticed that when a youtube page crashes, it gives a kind of coded message that can be sent to Youtube developers without letting customers know about the Youtube infrastructure and the programs used.

Is this idea a practice for your own sites?

+2
source share
3 answers

You do not need this with PHP.
Unlike Flash, PHP runs on the server side. So, just do PHP to log any error messages.
Set these parameters in php.ini file

log_errors = On display_errors = Off 

and you don’t need volunteer users to see them
but only your web server error log to look at

+2
source

Most frameworks currently have the ability to use various application parameters for use in production and development.

In production mode (when the site is used by customers) errors should not be visible for security and design reasons. Therefore, you often include log_errors and display_errors. When a fatal error occurs, the user gets something like "Something went wrong, we immediately put our best people on it." It makes no sense to show the user some strange number, for example, "Error code 823." Use cron worker to send you an error log or simply check the log manually and make sure that the error messages are detailed enough for you to track the error.

In development mode (when you start the site locally during development), you probably want to see errors as soon as they appear. Therefore, you enable display_errors. You probably won’t mind if the design breaks, and I hope you understand what is happening.

Error messages are a programmer's best friend, but your users should never try them out. If this happens, make sure the user gives us reasonable feedback, not just a blank page or a random error code.

+2
source

Just thought of creating a custom error handler using some basic encoding / decoding function so you can expand on 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')); 
0
source

All Articles