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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
$url = "http://www.regeco.fr/"; // => home_news.aspx [PAS OK]
//$url = "http://www.ctcmarketingweb.com"; // => http://ctcmarketingweb.com [OK]
//$url = "http://www.jt-artisan.com"; // => http://www.jt-artisan.com/index.html [OK]
class HTTPReader
{
protected $_url = null;
protected $_headers = array();
protected $_body = '';
public function __construct($url,$referer='') {
$this->_url = curl_init($url);
curl_setopt($this->_url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->_url, CURLOPT_HEADER, false);
curl_setopt($this->_url, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->_url,CURLOPT_REFERER,$referer);
curl_setopt($this->_url, CURLOPT_HEADERFUNCTION,array($this, 'readHeaders'));
}
public function __destruct() {
curl_close($this->_url);
}
public function getHeaders() {
$this->_body = curl_exec($this->_url);
return $this->_headers;
}
public function getBody() {
return $this->_body;
}
public function getInfo($info_type) {
$info = curl_getinfo($this->_url );
return $info[$info_type];
}
protected function readHeaders($url, $str) {
if (strlen($str) > 0) {
$this->_headers[] = $str;
}
return strlen($str);
}
}
$http = new HTTPReader($url);
$tHeaders = $http->getHeaders();
// On recherche si le document "has moved" en isolant la ligne Location:
foreach($tHeaders as $key=>$val)
{
if(strtolower(substr($val,0,9)) == "location:")
{
// Le document nous indique qu'il a été déplacé à un autre endroit, donc on jump jusqu'à ce nouvel endroit
$newLocation = substr($val,10);
}
}
echo"$newLocation";
?> |
Partager