file_get_contents() and MySQL question

file_get_contents() and MySQL question

Posted by: STHayden
Posted on: 2005-04-22 14:27:00

my website (www.stefanhayden.com/portfolio/metrocss/getvars.php) used the function file_get_contents() but after the anouncement of PHP's allow_url_fopen NOW Disabled (Action Required) by dreamhots it does not work.

first off am I right in assuming that that is the reason I can not grab external pages with file_get_contents()?

because I need the webpage to be functional for my final portfolio review in a week I wanted a quick fix and moved the page to my school's server which has not disabled the feature. Though I also want to connect to my dreamhost database. Can I connect to the database from an out side webhost? I have yet to make that work.

any help would be great as I need to fix this as fast as possible.

Re: file_get_contents() and MySQL question

Posted by: everinjoy
Posted on: 2005-04-22 17:09:00

Presumably you could edit the MySQL user to allow access from whatever IP your school server is on.

Re: file_get_contents() and MySQL question

Posted by: scjessey
Posted on: 2005-04-22 18:00:00

In reply to:

My website used the function file_get_contents() but after the anouncement of PHP's allow_url_fopen NOW Disabled (Action Required) by dreamhost it does not work. First off am I right in assuming that that is the reason I can not grab external pages with file_get_contents()?


I believe the answer is yes. You should be able to get around this problem by using the bundled cURL library. I'm not familiar with cURL, but after a little bit of digging, I think this may help you.

Instead of:

$file_contents = file_get_contents('http://example.com/');
echo $file_contents;

Use this:

$handle = curl_init();
curl_setopt ($handle, CURLOPT_URL, 'http://example.com');
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
$file_contents = curl_exec($handle);
curl_close($handle);
echo $file_contents;

Doodz who are more familiar with cURL should check this for me, but I think it is more or less correct.

Tags: phpdreamhostwebhostfopenassuminggrabwebpagemysqlurlactionwebsite www