Which error reporting to use?

When developing a site locally to go up live which php error reporting should i use?
Will it be different for each hosting provider or the default that comes with xampp?

I tend to work the other direction. I make sure my local setup matches my hosted/production setup. So if I need to build an error log process, I can do it up front, instead of assuming it will be setup in a certain way when I move it to my hosted/production server.

BEWARE - displaying PHP Errors may show useful site Online configurations and make your site hacker friendly :slight_smile:

Every hosting provider configures the php.ini file and sets the value of PHP error reporting. Fortunately error reporting and the associated display_errors can easily be changed to suit the environment.

Setting an environment specific CONSTANT can be used to have common files for both Local and Online environments. This makes it easier in only having a single file to maintain for both environments.



# phpinfo();  # displays php.ini settings

define( 'LOCALHOST', 'localhost' == $_SERVER['SERVER_NAME'] );

# set ONLINE defaults and override php.ini settings
    error_reporting(0);
    ini_set('display_errors', 0);

    if( LOCALHOST )
    {
        error_reporting( -1 );
        ini_set('display_errors', 1);

        # check settings
        require 'this-is-a-not-existent-file.php';
    }

C_P,

John is correct: NEVER report errors to hackers (who will try to break your site to facilitate hacking it). Test off line using the same server configuration if at all possible (that means NOT using canned programs that install everything for you as they’ll NEVER match your production environment), eliminate all the obvious errors, try to generate errors and test the responses THEN upload to the server.

Regards,

DK

I was more talking about what should I then use for my local settings.

I was working as part of a group for university and I came across a problem where on my machine no errors were displayed and when we were working on someone else machine there were errors like undefined variable showing up etc

Did you install the script from post #3 at the beginning of your program?

The error_reporting function returns an integer and you could test your settings with the following script:



<?php

echo '<br />', __LINE__, ' : ' , error_reporting(0);

echo '<br />', __LINE__, ' : ' , error_reporting(-1);

echo '<br />', __LINE__, ' : ' , error_reporting(E_ALL);

echo '<br />', __LINE__, ' : ' , error_reporting(E_WARNINGS);

die; # freezes the display and stops program execution


Well the other guy just had his standard settings from xampp.
I changed my xampp php.ini file to E_ALL i think but nothing was put in the sites php files.

I learned to change the php.ini file in the lynda php basics video