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

Before
file_get_contents

After
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
  • del.icio.us

Posted in Uncategorized | 4 Comments »

Related Posts

4 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 phpcode.mypapit.net/how-to-solve-file_ge…-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[...] http://www.kevinkorb.com/post/3 http://phpcode.mypapit.net/how-to-solve-file_get_contents-and-file-php-errors/45/ [...]

  3. www.mequoda.com Additional Info additional reading Check Out www.mequoda.com Check This Out Click at www.mequoda.com Click At this website click for source Click Here Click In this article Click on www.mequoda.com 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.

Leave a Comment

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