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 |

Related Posts

3 Responses

  1. toydi Says:

    the first two links seem not pointing to any file.

  2. mypapit Says:

    dang must have misplaced it somewhere, going to repair it in two days…

    thanks toydi!

  3. Svetoslav Marinov Says:

    I will add Snoopy

    it uses fsockopen and external cURL binary (I checked that several months ago)

    http://snoopy.sourceforge.net/

Leave a Comment

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