File_get_contents() and MySQL question


#1

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.


#2

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


#3

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.


Simon Jessey
Keystone Websites | si-blog