private function curl_exec_follow($ch) { if (self::$_loops++ >= self::$_maxLoops) { self::$_loops = 0; return false; } $data = curl_exec($ch); $temp = $data; list($header, $data) = explode("\n\n", $data, 2); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http == 301 || $http == 302) { $matches = array(); preg_match('/ocation:(.*?)\\n/', $header, $matches); $url = @parse_url(trim(array_pop($matches))); // print_r($url); if (!$url) { self::$_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'] : ''); // echo "\n redirect to ".$new_url; //@todo Возможна непредвиденая хуйня. curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_URL, $new_url); return $this->curl_exec_follow($ch); } else { self::$_loops = 0; return $temp; } }