[英]PHP error handling with .htaccess & writing into php_error.log text file
对于PHP错误处理,其目的是“只有管理员才能看到警告,错误等”。
我应用了以下步骤:
error_reporting(-1);
来自我的index.php
命令 public_html
文件夹下的.htaccess
添加了以下行 public_html
文件夹中创建了error_modes
文件夹 error_modes
文件夹中创建了.htaccess
文件 error_modes
文件夹的权限设置为777
可写。 footer.inc.php
页面中写了<?php 'should see this error in log file' ?>
。 请注意我没有写信;
字符结尾。 尽管我的footer.inc.php
页面中故意存在php语法错误 ,但没有创建php_error.log
文件!
并且我看到应该在footer.inc.php
页面中打印了日志文件 string
此错误 。 因此,尽管存在语法错误,php仍能正常工作!
我还在下面添加了整个.htaccess
代码。 (这是位于public_html
下的那个)
仅供参考 :我没有访问php.ini
权限,也没有任何预设的.log
文件。 PHP版本是5.4。
你能纠正我吗? 谢谢。 最好的祝福。
php_flag log_errors on
php_flag display_errors off
php_value error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1
Order allow,deny
Deny from all
RewriteEngine On
RewriteBase /
#always use www - redirect non-www to www permanently
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css|js)$ - [NC,F,L]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# disable directory browsing
Options All -Indexes
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# secure password file
<Files .mypassword>
order allow,deny
deny from all
</Files>
# secure spesific files
<Files secret.php>
order allow,deny
deny from all
</Files>
# secure spesific files
<Files secret2.php>
order allow,deny
deny from all
</Files>
#SEO friendly linking
RewriteRule ^sitemap.xml$ sitemap.php [L]
RewriteRule ^articles/(.+)/(.+)$ index.php?page=articles&subject=$1&object=$2 [L]
RewriteRule ^articles/(.+)$ index.php?page=articles&subject=$1 [L]
RewriteRule ^labels/(.+)$ index.php?page=labels&subject=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)$ index.php?page=$1 [L]
#error handling
php_flag log_errors on
php_flag display_errors off
php_value error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1
请尝试执行以下操作:
# supress php errors
php_flag display_startup_errors off
php_flag display_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 /correct_path_to_your_website/error_modes/PHP_errors.log
# general directive for setting php error level
php_value error_reporting -1
除了在您的php文件中编写的故意错误之外,您可以尝试执行以下操作:
<?
echo $_SERVER['DOCUMENT_ROOT']; // this will enable you to see
// the correct path to your website dir
// which should be written in .htaccess
// instead of correct_path_to_your_website
// (check it just in case)
$foo = $bar['nope'];// this should generate notice
call_undefined(); // this should generate fatal error
?>
和我一起工作很好)
希望能对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.