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.
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.
Posted in Uncategorized | 11 Comments »