PHP错误处理的.htaccess和放大器;写入php_error.log文本文件放大器、文本文件、错误、PHP

2023-09-02 10:05:07 作者:难熬

有关使用的目的是PHP错误处理只有管理员看到警告,错误等。

我申请以下步骤:

在我删除使用error_reporting(-1); 从命令我的index.php 在我添加的行下面进入我的的.htaccess 这仅仅是在的public_html 文件夹 我在创建 error_modes 文件夹中的public_html 文件夹 在我创建的的.htaccess 文件 error_modes 文件夹 我设置了​​ error_modes 文件夹的权限 777 ,可写的。 有意,我写了< PHP的应该看到日志文件中此错误'>?在我的 footer.inc.php 页。请注意,我不写了; 字符结束

尽管有意 PHP语法错误我 footer.inc.php 页,否 php_error.log 文件被创建!

和我看到的应该看到日志文件中此错误的的字符串的印在我的页脚。 inc.php 页。因此,PHP的工作,尽管有语法错误!?

我还加了我的整个的.htaccess code以下。 (这是一个只有在的public_html

仅供参考:我没有获得的php.ini 和我没有任何pre-集 .LOG 文件。 PHP版本是5.4。

能否请你指正?谢谢。顺祝商祺。

添加命令到的public_html>的.htaccess用于错误处理

 的php_flag log_errors上
的php_flag display_errors设置关闭
php_value的error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value的error_reporting -1
 

codeS里error_modes>的.htaccess

 订购允许,拒绝
所有拒绝
 
写php代码,显示这个是怎么回事

全codeS里的public_html>的.htaccess

  RewriteEngine叙述上
的RewriteBase /

#always使用WWW  - 重定向非www到www永久
的RewriteCond%{HTTP_HOST}!^ WWW 。
的RewriteCond%{} HTTPS S上(S)|
重写规则^ HTTP%1://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L]


#盗链保护
的RewriteCond%{HTTP_REFERER}!^ $
的RewriteCond%{HTTP_REFERER} ^ HTTP(S):!?(WWW )?// mydomain.p.ht [NC]
。重写规则(JPG | JPEG | PNG | GIF | CSS | JS)$  -  [NC,F,L]

#COM preSS文本,HTML,JAVASCRIPT,CSS,XML:
AddOutputFilterByType DEFLATE text / plain的
AddOutputFilterByType DEFLATE text / html的
AddOutputFilterByType DEFLATE为text / xml
AddOutputFilterByType DEFLATE文/ CSS
AddOutputFilterByType DEFLATE应用程序/ XML
AddOutputFilterByType DEFLATE是application / xhtml + xml的
AddOutputFilterByType DEFLATE应用程序/的RSS + XML
AddOutputFilterByType DEFLATE应用程序/ JavaScript的
AddOutputFilterByType DEFLATE应用程序/ x-j​​avascript的

#文件缓存是优化网站的加载时间另一个著名的方法
< FilesMatch(FLV | GIF | JPG | JPEG | PNG | ICO |瑞士法郎| JS | CSS | PDF)$。>
页眉设置缓存控制最大年龄= 2592000
< / FilesMatch>

#禁止目录浏览
选项​​所有-Indexes

#安全htaccess文件
<文件的.htaccess>
 为了允许,拒绝
 所有否认
< /文件>

#安全的密码文件
<文件.mypassword>
 为了允许,拒绝
 所有否认
< /文件>

#安全spesific文件
<文件secret.php>
 为了允许,拒绝
 所有否认
< /文件>

#安全spesific文件
<文件secret2.php>
 为了允许,拒绝
 所有否认
< /文件>

#SEO友好链接
重写规则^ sitemap.xml的$ sitemap.php [L]
重写规则^文章/(.+)/(.+)$ index.php页面=文章&功放;主题= $ 1安培;目标= $ 2 [L]
重写规则^文章/(.+)$ index.php页面=文章&功放;主题= $ 1 [L]
重写规则^标签/(.+)$ index.php页面=标签和放大器;主题= $ 1 [L]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^ /?([^ /] +)$的index.php?网页= $ 1 [L]

#ERROR处理
的php_flag log_errors上
的php_flag display_errors设置关闭
php_value的error_log /home/my_user_number/public_html/error_modes/php_error.log
php_value的error_reporting -1
 

解决方案

请尽量做到以下几点:

在.htaccess

 #苏preSS PHP错误
    的php_flag display_startup_errors关闭
    的php_flag display_errors设置关闭
    php_value docref_root 0
    php_value docref_ext 0


    #启用PHP错误日志记录
    的php_flag log_errors上
    php_value的error_log /correct_path_to_your_website/error_modes/PHP_errors.log


    #通用指令设置PHP的错误级别
    php_value的error_reporting -1
 

在php文件

而不是在你故意的错误在你的PHP文件中写道,你可以尝试做这样的事情:

 &LT ;?

    回声$ _ SERVER ['DOCUMENT_ROOT']; //这将让你看到
                                    //正确的路径到你的网站目录
                                    //应写在.htaccess
                                    //代替correct_path_to_your_website
                                    //(检查,以防万一)

    $ FOO = $条['没了']; //这应该生成通告

    call_undefined(); //这应该产生致命错误


    ?>
 

曾好与我)

希望能对大家有所帮助。

For PHP error handling with the aim of "only admin sees the warnings, errors etc.";

I applied the steps below:

I deleted error_reporting(-1); command from my index.php I added rows below into my .htaccess which is just under public_html folder I created error_modes folder in my public_html folder I created .htaccess file in error_modes folder I set the permissions of the error_modes folder as 777, writable. intentionally, I wrote <?php 'should see this error in log file' ?> in my footer.inc.php page. Please note that I didn't wrote ; character at the end.

Despite the intentional php syntax error in my footer.inc.php page, no php_error.log file is created!

and I saw that should see this error in log file string is printed in my footer.inc.php page. So php worked despite a syntax error !?

I also added my whole .htaccess code below. (this is the one that is just under public_html)

fyi: I don't have access to php.ini and I don't have any pre-set .log file. PHP version is 5.4.

Can you please correct me? Thanks. Best Regards.

added commands into public_html > .htaccess for 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

codes in error_modes > .htaccess

Order allow,deny
Deny from all

whole codes in 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

解决方案

Please try to do the following:

In .htaccess

    # 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

In php file

Instead of intentional mistake in you wrote in your php file you can try doing something like:

    <?

    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


    ?>

Worked good with me)

Hope it'll help.