Jump to content

File_Get_Contents Warnings

Bob Crabb

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...