1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
function httpGetPage($url) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_MAXREDIRS, 10);
curl_setopt($c, CURLOPT_TIMEOUT, 10);
$content = curl_exec ($c);
$info = curl_getinfo($c);
curl_close ($c);
$status = $info['http_code'];
$headers_bloc = trim(substr($content, 0, $info['header_size']));
$hlines = explode("\n", $headers_bloc);
$headers = array();
for($i=1;$i<count($hlines);$i++) {
list($key, $value) = explode(':', $hlines[$i], 2);
$headers[trim($key)] = trim($value);
}
$html = substr($content, $info['header_size']);
return array($status, $headers, $html);
}
list($status, $headers, $html) = httpGetPage($url);
if($status>=400) die("Non trouvé");
echo "Trouvé";
print_r($headers); |
Partager