Jump to content

cURL the file_get_contents


CrossX

Recommended Posts

Instead of:

file_get_contents on the script above

 

Use this:

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, '$adr');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

 

 

In a measure to improve security, my host has disabled the PHP option allow_url_fopen.

 

and the alternative for me is tu use cURL

 

Instead of use "file_get_contents" i have to find another method!

 

 

my function is:

 

function my_external_link($id, $redirect = false) {
    $url = 'http://www.example.com/video?f='.$id;
    if ($html = file_get_contents($url)) {
        if (preg_match('/\/player2\.swf\?video_id=.*?&t=(.*?)"/', $html, $match)) {
            $url = 'http://youtube.com/get_video.php?video_id='.$id.'&t='.$match[1];
            if ($redirect && $redirected_url = get_redirected_url($url)) {
                $url = $redirected_url;
            }
            return $url;
        }
    }
    return false;
}

 

but with; file_get_contents im having this error:

 

URL file-access is disabled in the server configuration in

 

did someone understand me?

 

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.