- $newurl = $curl_info['redirect_url'];
-
- if (($new_location_info['path'] == '') && ($new_location_info['host'] != '')) {
- $newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path'];
- }
-
- $matches = [];
-
- if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) {
- $newurl = trim(array_pop($matches));
- }
- if (strpos($newurl, '/') === 0) {
- $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
- }
- $old_location_query = @parse_url($url, PHP_URL_QUERY);
-
- if ($old_location_query != '') {
- $newurl .= '?' . $old_location_query;
- }
-
- if (filter_var($newurl, FILTER_VALIDATE_URL)) {
- $redirects++;
- @curl_close($ch);
- return self::curl($newurl, $binary, $redirects, $opts);
- }
- }
-
- $a->set_curl_code($http_code);
- $a->set_curl_content_type($curl_info['content_type']);
-
- $rc = intval($http_code);
- $ret['return_code'] = $rc;
- $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
- $ret['redirect_url'] = $url;
-
- if (!$ret['success']) {
- $ret['error'] = curl_error($ch);
- $ret['debug'] = $curl_info;
- logger('error: '.$url.': '.$ret['return_code'].' - '.$ret['error'], LOGGER_DEBUG);
- logger('debug: '.print_r($curl_info, true), LOGGER_DATA);
- }
-
- $ret['body'] = substr($s, strlen($header));
- $ret['header'] = $header;
-
- if (x($opts, 'debug')) {
- $ret['debug'] = $curl_info;