Change PHP Error Levels in Your Web Site ?

Hey!

Have you ever wonder whether the PHP Error Messaging is important to you (developer) but not the end user ? but, it keeps coming ? to both ?

or

Have you ever wanted to display your own error message to the User instead of PHP default ?

or

Completely remove PHP Errors?


Then, this is the way to go. To change the error levels you must be PHP admin as well as must be able to access your php.ini file. For now, let's imagine you use xampp installed  in your system & you use localhost.

if you use Linux, you'll find your php.ini in /opt/lampp/etc

or

if you use windows you'll find it C:\xampp\php.

Open the file with admin privileges. (In Linux use sudo nautilus command in terminal) Then, find something like follows.

error_reporting = E_ALL | E_STRICT

display_errors = On


This statement is responsible for invoking all error,warnings & notices. E_ALL is a built in php constant & it stands for all errors.

Now, change on to off. Try changing following as well.

display_startup_errors = On  

Specially, you can comment one of these lines & check whether it works. Example is given below.


;error_reporting = E_ALL | E_STRICT
;display_errors = On
;display_startup_errors = On

Standard Commenting inside php.ini file is done using  ';' (Semicolon). During this process you'll need to stop and restart already running web server.

So,if you need to Change PHP Error Levels in a Script not in your Web Site. Then take a look at following Code.

        
<?php
            
        error_reporting(E_ALL & ~E_NOTICE);

        $var="2012-11-30";

        echo $var;

        echo $var2;

?>

or
        
<?php
            
        error_reporting(0);

        $var="2012-11-30";

        echo $var;

        echo $var2;

?>

In the above examples error_reporting() fundamentally changes error levels in the script itself.

To Change PHP Error message to a log. Go to php.ini again 7 Check for the following.
log_errors = Off

Change Off to On. Then, tell PHP to send error messages to a particular location by editing following code. Remove ; at the first place.

;error_log = filename

Set it as follows.

error_log = c:\temp\php_error_log

No comments: