0); curl_setopt($ch, CURLOPT_MAXREDIRS, $mr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } else { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); if ($mr > 0) { $original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $newurl = $original_url; $url_data = parse_url($newurl); if (!empty($url_data['user']) and !empty($url_data['pass'])){ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); curl_setopt($ch, CURLOPT_USERPWD, $url_data['user']. ":" . $url_data['pass']); $newurl = $url_data['scheme'] . '://' . $url_data['host']; if (!empty($url_data['port'])){ $newurl .= ':' . $url_data['port']; } $newurl .= $url_data['path']; if (!empty($url_data['query'])) { $newurl .= '?' . $url_data['query']; } } $rch = curl_copy_handle($ch); curl_setopt($rch, CURLOPT_HEADER, true); curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); curl_setopt($rch, CURLOPT_CONNECTTIMEOUT, 5); do { curl_setopt($rch, CURLOPT_URL, $newurl); $header = curl_exec($rch); if (curl_errno($rch)) { $code = 0; } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); // if no scheme is present then the new url is a // relative path and thus needs some extra care if(!preg_match("/^https?:/i", $newurl)){ $newurl = $original_url . $newurl; } } else { $code = 0; } } } while ($code && --$mr); curl_close($rch); if (!$mr) { if ($maxredirect !== null) $maxredirect = 0; return false; } curl_setopt($ch, CURLOPT_URL, $newurl); } } return curl_exec($ch); } endif;