How to solve file_get_contents and file() PHP errors
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: curl, php, remote, security, php scripts, web hosting, web
Posted in Uncategorized |








May 23rd, 2007 at 8:53 pm
the first two links seem not pointing to any file.
May 24th, 2007 at 1:24 am
dang must have misplaced it somewhere, going to repair it in two days…
thanks toydi!
May 31st, 2007 at 1:56 pm
I will add Snoopy
it uses fsockopen and external cURL binary (I checked that several months ago)
http://snoopy.sourceforge.net/