Вход Регистрация
Файл: public_html/youtube/youtube/classes/curl.php
Строк: 31
<?php

// Костыль
function curl_redir_exec($ch) {
    static 
$curl_loops = 0;
    static 
$curl_max_loops = 20;
    if (
$curl_loops >= $curl_max_loops) {
        
$curl_loops = 0;
        return 
false;
    }
    
curl_setopt($ch, CURLOPT_HEADER, true);
    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
$data = curl_exec($ch);
    list(
$header, $data) = preg_split("%(nn|rnrn)%", $data, 2);
    
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if (
$http_code == 301 || $http_code == 302) {
        
$matches = array();
        
preg_match('/Location:(.*?)n/', $header, $matches);
        
$url = @parse_url(trim(array_pop($matches)));
        if (!
$url) {
            
$curl_loops = 0;
            return 
$data;
        }
        
$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
        if (!
$url['scheme'])
            
$url['scheme'] = $last_url['scheme'];
        if (!
$url['host'])
            
$url['host'] = $last_url['host'];
        if (!
$url['path'])
            
$url['path'] = $last_url['path'];
        
$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query'] ?
            
'?' . $url['query'] : '');
        
curl_setopt($ch, CURLOPT_URL, $new_url);
        return 
curl_redir_exec($ch);
    } else {
        
$curl_loops = 0;
        return 
$data;
    }
}

////////////////////////////////////
/// CURL функция. Автор  Koenig/////
////////////////////////////////////
function curl($url, $file='', $post='', $mode=array()) {

    
$defaultmode = array('charset' => 'utf-8', 'ssl' => 0, 'cookie' => 0, 'headers' => 1, 'useragent' => 'Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.10.229 Version/11.61');

    foreach (
$defaultmode as $k => $v) {
        if (!isset(
$mode[$k]) ) {
            
$mode[$k] = $v;
        }
    }

    
$ch = curl_init();
    
curl_setopt($ch, CURLOPT_URL, $url);
    
curl_setopt($ch, CURLOPT_HEADER, $mode['headers']);
    
curl_setopt($ch, CURLOPT_REFERER, $url);
    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
curl_setopt($ch, CURLOPT_USERAGENT, $mode['useragent']);
    
curl_setopt($ch, CURLOPT_ENCODING, $mode['charset']);
    
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
    if (
$file) {
        
curl_setopt($ch, CURLOPT_FILE, $file);
    }
    if (
$post) {
        
curl_setopt($ch, CURLOPT_POST, 1);
        
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if (
$mode['cookie']) {
        
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
        
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
    }
    
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    
    
// подключаем до работы костыль
    
if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
       
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    } else {
       
curl_redir_exec($ch);
    }
    
    if (
$mode['ssl']) {
        
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    }
    
$data = curl_exec($ch);
    
curl_close($ch);
    return 
$data;
}
Онлайн: 2
Реклама