lip9000 Posted May 11, 2008 Share Posted May 11, 2008 Hey guys I've tried both fopen and file_get_contents in this function to get the contents of a URL, and both are rejected by my host (Godaddy). Warning: fopen(): URL file-access is disabled in the server configuration i..... Warning: file_get_contents(): URL file-access is disabled in the server configuration i.... The script pulls the title from a youtube page, it goes as follows: $str = file_get_contents($url); $begin = strpos($str, "<title>"); $end = strpos($str, "</title>"); $title = substr($str, $begin+17, $end-192); What alternative functions can I use to get the contents of the file??? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 11, 2008 Share Posted May 11, 2008 cURL? Sockets? Move host? Quote Link to comment Share on other sites More sharing options...
lip9000 Posted May 11, 2008 Author Share Posted May 11, 2008 Could you please elaborate on that a bit more, like maybe a specific function if there is another one that godaddy supports. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 11, 2008 Share Posted May 11, 2008 Call me old fashioned, but you could always try the manual: cURL sockets Now, i'm unsure if the setting allow_url_fopen needs to be on for the use of cURL/sockets (it appears to be off with your host) but either way i wouldn't be surprised if you can't use these either. You might wish to contact your host and find out if the above setting can be changed. Quote Link to comment Share on other sites More sharing options...
lip9000 Posted May 11, 2008 Author Share Posted May 11, 2008 would this be correct? <?php $url = 'http://www.google.com/'; $ch = curl_init(); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set the URL curl_setopt($ch, CURLOPT_URL, $URL); //Execute the fetch $data = curl_exec($ch); //Close the connection curl_close($ch); //$data now contains the contents of $URL print $data; ?> I tried uploading and testing that but it just gives me a blank page, no errors though. I tried echo instead of print and that did nothing either. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 11, 2008 Share Posted May 11, 2008 Yeah, you'll need to echo out the curl_error to check for errors. Also, this line: curl_setopt($ch, CURLOPT_URL, $URL); Should be: curl_setopt($ch, CURLOPT_URL, $url); Quote Link to comment Share on other sites More sharing options...
lip9000 Posted May 11, 2008 Author Share Posted May 11, 2008 Thanks mate, stupid me it was the variable name! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.