好吧更新了所有內容。我用這個功能:檢索該頁面的重定向
private function get_follow_url($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$a = curl_exec($ch);
if(preg_match('Location:(.*)', $a, $r)){
$url=trim($r[1]);
$this->get_follow_url($url);
}
return $a;
}
我得到這個當附和道:
HTTP/1.1 301 Moved Permanently Server: nginx/0.7.67 Date: Sun, 14 Oct 2012 10:03:21 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.2.17 X-Pingback: http://thesexguy.com/xmlrpc.php Location: http://example.com/mature Content-Length: 0
所以我做一個遞歸..並嘗試刮定位字後再次讀取該網頁...
它應該帶我到遞歸http://example.com/mature?我對嗎?但我沒有刮掉位置的單詞..爲什麼?
看看[Make curl follow redirects?](http://stackoverflow.com/questions/3519939/make-curl-follow-redirects) – Killrawr