Jump to content

How to hide php errors


HTF

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

phpinfo_1260523973304.jpg

-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

 

Link to comment
Share on other sites

[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. :P[/ot]
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.