Jump to content

fopen and file_get_contents alternatives


lip9000

Recommended Posts

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???

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.

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.