SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,824
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Cyanide_Pierce View Post
    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?
    BEWARE - displaying PHP Errors may show useful site Online configurations and make your site hacker friendly

    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.

    PHP Code:

    # 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( -);
            
    ini_set('display_errors'1);

            
    # check settings
            
    require 'this-is-a-not-existent-file.php';
        } 
    Last edited by John_Betong; Jun 30, 2012 at 00:56. Reason: included trailing slash in closing square PHP brackets

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,824
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Cyanide_Pierce View Post
    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 Code:

    <?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

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •