Jul 12, 2011

How to display errors while the display_errors is off in the php.ini file

Display_error feature is turned off or disabled mainly by your web hosting ISP or provider from the php.ini file. I hope this small tutorial will be of great help to display your php errors.

php.ini file will contain code some what like this

; display_errors = Off [Security]
; With this directive set to off, errors that occur during the execution of
; scripts will no longer be displayed as a part of the script output, and thus,
; will no longer be exposed to remote users. With some errors, the error message
; content may expose information about your script, web server, or database
; server that may be exploitable for hacking. Production sites should have this
; directive set to off.

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = On

Considering some security issues display_errors is usually disabled  by many web hosting companies in order to protect your website from any harm. One way to display errors while the display_errors is off in the php.ini file, is to add these functions at the beginning of your script files .

Just copy and paste this code at the beginning of your script files.

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

And thats it you can now display errors.

No comments :

Post a Comment