2010-11-29 33 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