1

Is there a way to disable error reporting when my site is on my actual host where people can view it and enable it when I'm just working on it locally on my usb webserver?

I find it a pain to constantly toggle between error_reporting(1) and (0) whenever I want to debug. I have it set in my connection file which is included on every page on my website btw

EDIT: Ended up adding this to my connection file

$addrip = $_SERVER['REMOTE_ADDR'];

if($addrip == "::1" || $addrip == "127.0.0.1" ){
    error_reporting(0);
}else{
    error_reporting(1);
}
Crecket
  • 718
  • 2
  • 7
  • 24
  • Configure your `php.ini` file in that way if you have access to it on your actual host. Do you? – D4V1D Mar 28 '15 at 18:27
  • No I don't think so, Ill ask my host about it though. Thanks :) – Crecket Mar 28 '15 at 18:30
  • 1
    You can disable them within your `.htaccess` file though: http://stackoverflow.com/questions/8652933/how-to-disable-notice-and-warning-in-php-within-htaccess-file – D4V1D Mar 28 '15 at 18:31
  • Well I know how to disable my errors but I would like to make it so that it toggles depending if I work online on my host or locally on my webserver. Pretty sure it would disable for both if I use htaccess – Crecket Mar 28 '15 at 18:33
  • I meant to use different `.htaccess` files depending on the host, of course. – D4V1D Mar 28 '15 at 18:33
  • 2
    Maybe something like `if ($_SERVER['HTTP_HOST'] == 'localhost'){...} else{...}` - or `$whitelist = array( '127.0.0.1' ); if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){ // not valid }` – Funk Forty Niner Mar 28 '15 at 18:34
  • @Fred-ii- I created something similar myself so I guess thats my solution, if you post this as a answer ill flag it as the solution :) – Crecket Mar 28 '15 at 18:42
  • @Crecket It has been done. Glad to hear that I could help out, *cheers* – Funk Forty Niner Mar 28 '15 at 18:46

2 Answers2

0

An often used solution is to include a config file, defining your environment (Development / Production) and setting error_error reporting accordingly. You should only synchronize the rest of your application, but leave different configurations on your local and remote machine!

ranopalepu
  • 16
  • 1
0

"@Fred-ii- I created something similar myself so I guess thats my solution, if you post this as a answer ill flag it as the solution :)"

As per OP's request to post my comment as an answer:

You can use any of these:

if ($_SERVER['HTTP_HOST'] == 'localhost')

    { 
    // do something
    }

    else
    {  
    // do something else
    }

or:

$whitelist = array( '127.0.0.1' ); 

if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist))
    {  
    // do something
    }

    else
    {  
    // do something else
    }
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141