以“只有管理员才能看到警告、错误等”为目标的 PHP 错误处理;
我应用了以下步骤:
- 我从我的删除
error_reporting(-1);命令index.php - 我将下面的行添加到我的文件夹
.htaccess下public_html - 我
error_modes在我的文件夹中创建了文件public_html夹 - 我在
.htaccess文件error_modes夹中创建了文件 error_modes我将文件夹的权限设置为777,可写。- 我故意
<?php 'should see this error in log file' ?>在我的footer.inc.php页面上写了。请注意,我最后没有写;字符。
尽管我的页面中有故意的php 语法错误,但没有创建任何文件!footer.inc.phpphp_error.log
我看到应该看到日志文件 string中的这个错误打印在我的footer.inc.php页面中。所以尽管语法错误,php仍然有效!?
我还在.htaccess下面添加了我的整个代码。(这是下面的那个public_html)
仅供参考:我无权访问,php.ini也没有任何预设.log文件。PHP版本是5.4。
你能纠正我吗?谢谢。此致。
将命令添加到 public_html > .htaccess 以进行错误处理
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
error_modes > .htaccess 中的代码
Order allow,deny
Deny from all
public_html > .htaccess 中的全部代码
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