0

好的全部更新了。我使用这个功能:

    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进行递归吗?我对吗?但是我没有刮掉位置词..为什么?

4

1 回答 1

2

您需要使用CURLOPT_FOLLOWLOCATION或设置 cURL 来检索完整的标头 ( CURLOPT_HEADER) 并解析Location标头。

于 2012-10-14T09:36:02.653 回答