PHP offers simple but effective solution to log all errors to a log file. On all production web server it is a must that you turn off displaying error to end users via a web browser. Remember PHP gives out lots of information about path, database schema and all other sort of sensitive information. You are strongly advised to use error logging in place of error displaying on production web sites. The idea is quite simple -only developer should see php error log.
The way I choose to do it is by having a common config.php file containing this code and included in the first line of every page.
// Display no errors in runtime pages ini_set("display_errors" , "0"); // Log errors to file ini_set("log_errors" , "1"); // Error log file path and name ini_set("error_log" , "logs/Errors.log.txt");
Good luck!!!
Latest posts by Abhishek Gupta (see all)
- PHP syntactic sugar code example - September 5, 2021
- Python convert random string date format to Datetime - July 12, 2021
- Laravel Custom Exception Handlers - March 28, 2019
One Reply to “Logging errors to file in PHP”