How can I disable notices and warnings in PHP within the .htaccess file?
It is probably not the best thing to do. You need to at least check out your PHP error log for things going wrong ;)
# PHP error handling for development 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
php_value error_reporting -1
php_value log_errors_max_len 0
Disable all php errors with htaccess file
Add the following line to your .htaccess file in the Root directory
php_value display_errors Off
This tells the apache web server to hide php errors for all directories and sub directories on the server.
How do I turn off PHP Notices?
You can disable notices by setting error reporting level to E_ALL & ~E_NOTICE;
using either error_reporting
ini setting or the error_reporting()
function.
However, notices are annoying (I can partly sympathize) but they serve a purpose. You shouldn't be defining a constant twice, the second time won't work and the constant will remain unchanged!
Turn off warnings and errors on PHP and MySQL
When you are sure your script is perfectly working, you can get rid of warning and notices like this: Put this line at the beginning of your PHP script:
error_reporting(E_ERROR);
Before that, when working on your script, I would advise you to properly debug your script so that all notice or warning disappear one by one.
So you should first set it as verbose as possible with:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
UPDATE: how to log errors instead of displaying them
As suggested in the comments, the better solution is to log errors into a file so only the PHP developer sees the error messages, not the users.
A possible implementation is via the .htaccess file, useful if you don't have access to the php.ini file (source).
# Suppress 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
# Enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
# Prevent access to PHP error log
<Files PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
Remove warning messages in PHP
You really should fix whatever's causing the warning, but you can control visibility of errors with error_reporting()
. To skip warning messages, you could use something like:
error_reporting(E_ERROR | E_PARSE);
Disable PHP in directory (including all sub-directories) with .htaccess
Try to disable the engine
option in your .htaccess file:
php_flag engine off
Related Topics
PHP Reflection - Get Method Parameter Type as String
Why Does File_Get_Contents Work with Google.Com But Not with My Site
How to Use Perl Libraries from PHP
Mysqli - Fetch_Array Error Call to a Member Function Fetch_Array() on a Non-Object MySQLi
How Does SQL-Injection Work and How to Protect Against It
Why Is My Number Value Changing Using Number_Format()
PHP - Add Two Hours to Date Variable
When and Where Should I Use Session_Start
Distance Calculations in MySQL Queries
Checking If 2 Arrays Have at Least 1 Equal Value
How to Overload Class Constructor Within Traits in PHP >= 5.4
Browscap Ini Directive Not Set