Bob Crabb Posted January 26, 2011 Share Posted January 26, 2011 I need some help. There is probably an easy solution for this, but I'm just not seeing it right now. I am doing a file_get_contents of a url to fill in an array variable. The program is working great, but in planning for a situation where there an error, like the url isn't available, or some other problem at the site where I am getting the information, I don't want errors to display on the page where I am using the array information. I have put in an if statement, checking for an empty array or a false return from the file_get_contents function. That will cause the script to go happily along doing something else, but when I test (by inserting an invalid url) the script works as expected, but I get warnings on the page. How can I capture the error and stop the warnings from displaying for this function? Quote Link to comment Share on other sites More sharing options...
Bob Crabb Posted January 26, 2011 Author Share Posted January 26, 2011 Nevermind ... I found a solution. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted January 26, 2011 Share Posted January 26, 2011 Glad you found a solution! Quote Link to comment Share on other sites More sharing options...
OJB Posted January 26, 2011 Share Posted January 26, 2011 I'm assuming your solution was error suppression using @ i.e. @file_get_contents()? Quote Link to comment Share on other sites More sharing options...
TCH-Dick Posted January 26, 2011 Share Posted January 26, 2011 Suppressing with @ does work, but I prefer to use trigger_error() to output custom errors without exposing too much. Quote Link to comment Share on other sites More sharing options...
Bob Crabb Posted January 26, 2011 Author Share Posted January 26, 2011 Yes, I used @. Seeing that it suppresses all errors, I don't really like using it, but in this case I think that it will be ok. What I am doing is using a geolocation api to get location information from the IP address of anyone visiting the site. Then I am using that information to customize some content. If the IP check fails, then the user sees the default content. I'm setting a $_SESSION parameter when the check is done so the function will only be called once per user visit. If the geolocation site is down, I didn't want error messages to appear on the page. Quote Link to comment 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.