Просмотр поста

.
-sanek-
# ValekS (06.03.2014 / 20:59)
Возникла проблема... На многих хостингах выдаёт:

И скрипт не работает. Пока даже не знаю как это решить. Отписал Коенигу. Проблема так то кажись в его классе КУРЛ.
Проблема не в классе Коенига, а в том что на многих хостах включены функции open_basedir и safe_mode. Я когда то тоже сталкивался с данной проблемой и находил в инете костыль.
Вот один из костылей (+/-)
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("%(\n\n|\r\n\r\n)%", $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;
    }
}
Ну и как-бэ само использование
$ua = "Opera/8.01 (J2ME/MIDP; Opera Mini/1.2.3214/1376; ru; U; ssr)";
$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[] = 'Connection: Close';
$header[] = 'Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1';
$header[] = 'Accept-Language: ru-RU,ru;q=0.9,en;q=0.8';

$ch = curl_init($url); 
curl_setopt_array($ch, array(
    CURLOPT_USERAGENT => $ua,
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_TIMEOUT => 15,
    CURLOPT_RETURNTRANSFER => 1
));

if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ch, CURLOPT_AUTOREFERER, false);
    $sh = curl_exec($ch);
} 
else
    $sh = curl_redir_exec($ch);

curl_close($ch);