Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

How to solve file_get_contents and file() PHP errors

May 18th, 2007 by Jon Moffet

file_get_contents() is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts.

However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws out an error which can render the whole web application useless in that particular web server.

To remedy this, you can replace file_get_contents() function with PHP cURL calls. Here's how you can do this.


CURL solution

Although the cURL version seems to be a little bit longer, it is guaranteed to work across servers which place restriction on file_get_contents() and file() function. The use of libcurlemu ensures that the script can work even on a server which doesn't have the PHP CURL extension, which makes this a universal solution for retrieving remote web content from PHP application.

Tags: , , , , , ,

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb

Posted in Uncategorized | 12 Comments »

Related Posts

12 Responses

  1. Geolocalization not working in my site (solved) Says:

    Kramer auto Pingback[...] providers set it to OFF for security reason (like mine) I found the solution in this article…-file-php-errors/45/ "To remedy this, you can replace file_get_contents() function with PHP cURL calls. …… [...]

  2. WordPress › Support » [Plugin: Facebook Comments to WordPress] allow_url_fopen not allow for many host - please change fil Says:

    Kramer auto Pingback[...] [...]

  3. Additional Info additional reading Check Out Check This Out Click at Click At this website click for source Click Here Click In this article Click on Click On this page Clicking Here Continue Says:

    Excellent blog here! Also your site loads up fast!
    What host are you using? Can I get your affiliate link to your
    host? I wish my site loaded up as fast as yours lol

  4. Free Date Says:

    Hi there, yeah this article is in fact nice and I have learned lot of things fdom it on the
    topic of blogging. thanks.

  5. program do faktur Says:

    After looking at a handful of the blog posts on your blog,
    I really like your way of writing a blog. I added it to my bookmark website list and will be checking back soon. Please visit my web site as well and
    tell me how you feel.

  6. dominio .ly Says:

    Hello, yes this paragraph is in fact good and I have learned lot of things
    from it on the topic of blogging. thanks.

  7. politie in beeld Says:

    certainly like your web site however you need to check the spelling on quite a few of your
    posts. Many of them are rife with spelling issues and I in finding it very bothersome to inform the reality
    nevertheless I will definitely come back again.

  8. Event Support Says:

    Thanks for finally writing about >How to
    solve file_get_contents and file() PHP errors ? Quick PHP Code
    Tips and Examples <Liked it!

  9. Arrestatieteam in actie Says:

    Aw, this was a very nice post. Taking the time and actual effort to produce a
    really good article… but what can I say… I put things off a lot and don’t manage to get nearly
    anything done.

  10. hosting Says:

    Hello friends, its great article regarding educationand
    completely defined, keep it up all the time.

  11. Says:

    The biggest advantage to in-office crown creations is inherent in the title.
    If the teeth are all a little stained, then the
    artificial tooth will be too. Regular implants are more invasive and take less time.

  12. Says:

    Your physique can use these healthy fat in a single day for regeneration and restore, which is necessary for maintaining healthy pores and skin and hair.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.