public static function getFileFromUrl() { $url = GS_Config::init()->get('ps_url'); if (!self::checkCurl()) { $opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n")); $context = stream_context_create($opts); return file_get_contents($url, false, $context); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $file = curl_redirect_exec($ch); curl_close($ch); return $file; }
private function _curl_redirect_exec($session) { $data = curl_exec($session); $info = curl_getinfo($session); if ($info['http_code'] == 301 || $info['http_code'] == 302) { list($header) = explode("\r\n\r\n", $data, 2); $matches = array(); preg_match('/(Location:|URI:)(.*?)\\n/', $header, $matches); $url = trim(array_pop($matches)); $url_parsed = parse_url($url); if (isset($url_parsed)) { curl_setopt($session, CURLOPT_URL, $url); return curl_redirect_exec($session); } } return $info; }
function curl_redirect_exec($ch) { if (ini_get('open_basedir') == '') { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); return curl_exec($ch); } $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { list($header) = explode("\r\n\r\n", $data, 2); $matches = array(); preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches); $url = trim(str_replace($matches[1], "", $matches[0])); if (is_array(parse_url($url))) { curl_setopt($ch, CURLOPT_URL, $url); return curl_redirect_exec($ch); } } return $data; }
function curl_redirect_exec($ch) { curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { list($header) = explode("\r\n\r\n", $data, 2); $matches = array(); //this part has been changes from the original preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches); $url = trim(str_replace($matches[1], "", $matches[0])); //end changes $url_parsed = parse_url($url); if (isset($url_parsed)) { curl_setopt($ch, CURLOPT_URL, $url); return curl_redirect_exec($ch); } } return $data; }