>Advance PHP Error with httaccess

February 1, 2011 at 11:46 pm | Posted in computer and high technology, Hacking | Leave a comment

>Prevent public display of PHP errors via htaccess

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

Preserve (log) your site’s PHP errors via htaccess

# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log

Protect your site’s PHP error log via htaccess

# prevent access to PHP error log   Order allow,deny  Deny from all  Satisfy All  

Controlling the level of PHP error reporting

Using htaccess, it is possible to set the level of error reporting to suit your particular needs. The general format for controlling the level of PHP errors is as follows:

# general directive for setting php error level
php_value error_reporting integer

Setting the maximum file size for your error strings

Using htaccess, you may specify a maximum size for your PHP errors. This controls the size of each logged error, not the overall file size. Here is the general syntax:

# general directive for setting max error size
log_errors_max_len integer
Disable logging of repeated errors

If you remember the last time you examined a healthy (or sick, depending on your point of view) PHP error log, you may recall countless entries of nearly identical errors, where the only difference for each line is the timestamp of the event. If you would like to disable this redundancy, throw down the following code in the htaccess file of your project root:

# disable repeated error logging
php_flag ignore_repeated_errors on
php_flag ignore_repeated_source on
Putting it all together — Production Environment

Having discussed a few of the useful ways to customize our PHP error-logging experience, let’s wrap it all up with a solid, htaccess-based error-handling strategy for generalized production environments. Here is the code for your target htaccess file:

# PHP error handling for production servers php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off php_flag log_errors on php_flag ignore_repeated_errors off php_flag ignore_repeated_source off php_flag report_memleaks on php_flag track_errors on php_value docref_root 0 php_value docref_ext 0 php_value error_log /home/path/public_html/domain/PHP_errors.log # [see footnote 3] # php_value error_reporting 999999999 php_value error_reporting -1 php_value log_errors_max_len 0    Order allow,deny  Deny from all  Satisfy All   Or, if you prefer, an explanatory version of the same code, using comments to explain each line:  # PHP error handling for production servers  # disable display of startup errors php_flag display_startup_errors off  # disable display of all other errors php_flag display_errors off  # disable html markup of errors php_flag html_errors off  # enable logging of errors php_flag log_errors on  # disable ignoring of repeat errors php_flag ignore_repeated_errors off  # disable ignoring of unique source errors php_flag ignore_repeated_source off  # enable logging of php memory leaks php_flag report_memleaks on  # preserve most recent error via php_errormsg php_flag track_errors on  # disable formatting of error reference links php_value docref_root 0  # disable formatting of error reference links php_value docref_ext 0  # specify path to php error log php_value error_log /home/path/public_html/domain/PHP_errors.log  # specify recording of all php errors # [see footnote 3] # php_value error_reporting 999999999 php_value error_reporting -1  # disable max error string length php_value log_errors_max_len 0  # protect error log by preventing public access   Order allow,deny  Deny from all  Satisfy All  

Putting it all together — Development Environment

During project development, when public access to your project is unavailable, you may find it beneficial to catch PHP errors in real time, where moment-by-moment circumstances continue to evolve. Here is a generalized, htaccess-based PHP error-handling strategy for development environments. Place this code in your target htaccess file:

# PHP error handling for development servers php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on php_flag log_errors on php_flag ignore_repeated_errors off php_flag ignore_repeated_source off php_flag report_memleaks on php_flag track_errors on php_value docref_root 0 php_value docref_ext 0 php_value error_log /home/path/public_html/domain/PHP_errors.log # [see footnote 3] # php_value error_reporting 999999999 php_value error_reporting -1 php_value log_errors_max_len 0    Order allow,deny  Deny from all  Satisfy All  

http://perishablepress.com/press/2008/01/14/advanced-php-error-handling-via-htaccess/

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: