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);
}
8
  • Configure your php.ini file in that way if you have access to it on your actual host. Do you? Commented Mar 28, 2015 at 18:27
  • No I don't think so, Ill ask my host about it though. Thanks :) Commented Mar 28, 2015 at 18:30
  • 1
    You can disable them within your .htaccess file though: stackoverflow.com/questions/8652933/… Commented Mar 28, 2015 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 Commented Mar 28, 2015 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 } Commented Mar 28, 2015 at 18:34

2 Answers 2

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
    }
Sign up to request clarification or add additional context in comments.

Comments

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.