PHP error handling with .htaccess & writing into php_error.log text file -


for php error handling aim of "only admin sees warnings, errors etc.";

i applied steps below:

  1. i deleted error_reporting(-1); command index.php
  2. i added rows below .htaccess under public_html folder
  3. i created error_modes folder in public_html folder
  4. i created .htaccess file in error_modes folder
  5. i set permissions of error_modes folder 777, writable.
  6. intentionally, wrote <?php 'should see error in log file' ?> in footer.inc.php page. please note didn't wrote ; character @ end.

despite intentional php syntax error in footer.inc.php page, no php_error.log file created!

and saw should see error in log file string printed in footer.inc.php page. php worked despite syntax error !?

i added whole .htaccess code below. (this 1 under public_html)

fyi: don't have access php.ini , don't have pre-set .log file. php version 5.4.

can please correct me? thanks. best regards.

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

whole codes in public_html > .htaccess

rewriteengine on rewritebase /  #always use www - redirect non-www 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 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 -indexes  # secure htaccess file <files .htaccess>  order allow,deny  deny </files>  # secure password file <files .mypassword>  order allow,deny  deny </files>  # secure spesific files <files secret.php>  order allow,deny  deny </files>  # secure spesific files <files secret2.php>  order allow,deny  deny </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 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 setting php error level     php_value error_reporting -1 

in php file

instead of intentional mistake in wrote in php file can try doing like:

    <?      echo $_server['document_root']; // enable see                                      // correct path website dir                                      // should written in .htaccess                                      // instead of correct_path_to_your_website                                     // (check in case)      $foo = $bar['nope'];// should generate notice       call_undefined(); // should generate fatal error       ?> 

worked me)

hope it'll help.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -