HTF Posted December 10, 2009 Share Posted December 10, 2009 Hello, How can I hide php errors like this below for example when I'm accesing my website(I've just changed index file extensions for this example purpose but I had such a errors before): PHP Warning: include(ip/index.pphp): failed to open stream: No such file or directory in C:\Web\DarkSpace\index.php on line 53 PHP Warning: include(): Failed opening 'ip/index.pphp' for inclusion (include_path='.;C:\php5\pear') in C:\Web\DarkSpace\index.php on line 53 Is it possible that instead of this the browser will be display some HTTP error like error 400 (Bad request) for example or somethomg like that, because in this case everybody see my directory structure ect. Regards Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/ Share on other sites More sharing options...
Mchl Posted December 10, 2009 Share Posted December 10, 2009 The best way is to make sure file exists before trying to include it. file_exists Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975057 Share on other sites More sharing options...
HTF Posted December 11, 2009 Author Share Posted December 11, 2009 Hello, Basically I have IP tool on my website that is showing visitors IP but I saw today that sometimes there is a slightly delay when the page is loading because of the website that provide the IP data, it's also displaying country flag ect. and I received php error about timing out (60 sec.) during loading the page so I would like to prevent from displaying this error or find some solution in situation when their website is slow what cause that my website is not loading. I've change 'the display_errors to off' in php.ini so I could prevent from displying any php errors but it's also not working. Your suggestion was great and I though that it will solve the problem but unfortunately not Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975133 Share on other sites More sharing options...
mrMarcus Posted December 11, 2009 Share Posted December 11, 2009 the best way to eliminate error messages is to write code that doesn't produce errors. merely disabling the error_reporting/display_errors is just suppressing the error(s), not making them go away. now, this is the file in question in your error: ip/index.pphp .. are you sure the extension should be: .pphp? instead of suppressing errors to eliminate the error message, why not just remove, or fix the code that's causing the error. in this case, either make sure the file exists, or remove the include(). simple. you best way to handle these errors would be to write conditions. <?php if ($timeout == true) { //do something; } else { //process something; } ?> get the idea? and unless you need the 'country flag', etc., don't accept it. only accepting the information you actually need will help speed things up on your site, bigtime. Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975152 Share on other sites More sharing options...
HTF Posted December 11, 2009 Author Share Posted December 11, 2009 Hello, Thank you for reply, I've just changed the php extension to generate an error for example. My goal is turn off any errors are displayed entirely for the security reason I've turned off display error in php.ini file: -but unfortunately I still see the errors? I also checked this code but it's not working: function errorHandling($message) { echo '<b>An error has occurred:</b><br><br><i>'; echo $message; echo '</i><br><br>Check your the settings in the db.php file and check your server is running correctly.<br>'; exit; } Can you help me with a code that will be redirecting to particular webpage if any error occur or at least shows some friendly message for the user Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975313 Share on other sites More sharing options...
Adam Posted December 11, 2009 Share Posted December 11, 2009 You may need to restart the web server for the changes to take effect? Edit: Oh wait. The image you posted shows it off.. Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975317 Share on other sites More sharing options...
Tazz Posted December 11, 2009 Share Posted December 11, 2009 Another way to get rid of errors is to suppress them, by putting an @ sign in front of the line of code that is producing the error. Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975347 Share on other sites More sharing options...
Mchl Posted December 11, 2009 Share Posted December 11, 2009 While it works, it's highly discouraged. Sweeping thrash under the bed is not the best way to tidy your room. Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975459 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 [ot] While it works, it's highly discouraged. Sweeping thrash under the bed is not the best way to tidy your room. Not the best analogy, sweeping trash under the bed quite clearly is the best way to tidy my room. [/ot] Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975491 Share on other sites More sharing options...
greatstar00 Posted December 12, 2009 Share Posted December 12, 2009 http://www.php.net/manual/en/function.set-error-handler.php try this, this is how error handling, i did it once you dont just write the function, u need to use the built-in function set_error_handler () Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975845 Share on other sites More sharing options...
oni-kun Posted December 12, 2009 Share Posted December 12, 2009 .. How about use CURL and set timeout to 5-10 seconds? If the result of the CURL function is a timeout, you can choose whatever you wish to display. Is this what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975849 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 I agree with mchl on this one. Just making errors go away is never a good idea IMO. There is a reason why it is giving you an error and maybe you should look into why it is giving you that error. If you write good code you should never see any php errors. You may not get the results that you want but you wont see an error for it. For example if you were to do this: $test = ''; foreach($test as $t){ //do something here } it will give you an error saying that there was invalid argument supplied (or something to that effect) because it is expecting an array but is getting a single value. But if you were to do this: $test = ''; if(is_array($test)){ foreach($test as $t){ //do something here } } else { echo 'not array'; } You will not get an error. That is called error handling. It first checks the variable test to see if it is an array and if it is it will loop. If it is not then it will just say not an array. But at no point will this throw an error and you can run it with ERRORS ON. But like I said you arent going to get the expected result if you dont pass it an array. Quote Link to comment https://forums.phpfreaks.com/topic/184689-how-to-hide-php-errors/#findComment-975852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.