2010-11-29 35 views
1

如何查找使用php的網站入站和出站鏈接的總數?如何查找使用php的網站入站和出站鏈接的總數?

+1

整個服務器範圍內的項目範圍?先生,該怎麼辦? – aefxx 2010-11-29 19:32:30

+0

我希望這對你有用。它用於查找入站和出站鏈接檢查程序的總數。找到[這裏](http://www.phphunger.com/2012/06/inbound-and-outbound-links-checker.html) – phphunger 2012-07-18 09:59:51

回答

0

PHP無法通過一些微不足道的操作確定頁面的入站鏈接。您必須監控所有來訪者並檢查他們的推薦人是什麼,或者解析整個互聯網尋找指向該網站的鏈接。第一種方法會丟失未使用的鏈接,第二種方法最好留給Google。

另一方面,站點的出站鏈接是可行的。您可以閱讀一個頁面並分析文本中的正則表達式鏈接,計算總數。

1

對於出站鏈接,你將不得不解析網站的HTML代碼,這裏的一些建議。

對於入站鏈接,我建議使用谷歌自定義搜索API,發送直接請求到谷歌可以讓你的IP被禁止。您可以查看搜索api here。下面是我在我的代碼中使用此API的功能:

function doGoogleSearch($searchTerm) 
    { 
    $referer = 'http://your-site.com'; 
    $args['q'] = $searchTerm;   
    $endpoint = 'web'; 
    $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; 

    $args['v'] = '1.0'; 
    $key= 'your-api-key'; 


    $url .= '?'.http_build_query($args, '', '&'); 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
    curl_setopt($ch, CURLOPT_REFERER, $referer); 
    $body = curl_exec($ch); 
    curl_close($ch); 
    //decode and return the response 
    return json_decode($body); 
    } 

調用此功能後:$result = doGoogleSearch('link:site.com'),變量$result->cursor->estimatedResultCount將返回結果的數量。

0
function getGoogleLinks($host) 
{ 

    $request = "http://www.google.com/search?q=" . urlencode("link:" . $host) ."&hl=en"; 

    $data = getPageData($request); 
    preg_match('/<div id=resultStats>(About)?([\d,]+) result/si', $data, $l); 
    $value = ($l[2]) ? $l[2] : "n/a"; 
    $string = "<a href=\"" . $request . "\">" . $value . "</a>"; 
    return $string; 
} 
//$host means the domain name