php获取谷歌PR值算法与php查询PR值的代码

原创
2016-07-25 08:57:43 940浏览
  1. /*
  2. *功能:对URL进行编码
  3. *参数说明:$web_url 网站URL,不包含"http://",例如jbxue.com
  4. */
  5. function HashURL($url){
  6. $SEED = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer.";
  7. $Result = 0x01020345;
  8. for ($i=0; $i{
  9. $Result ^= ord($SEED{$i%87}) ^ ord($url{$i});
  10. $Result = (($Result >> 23) & 0x1FF) | $Result }
  11. return sprintf("8%x", $Result);
  12. }
  13. /*
  14. *功能:获取pagerank
  15. *参数说明:$domain 网站域名,不包含"http://",
  16. */
  17. function pagerank($domain)
  18. {
  19. $StartURL = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank:&q=info:";
  20. // $StartURL = "http://www.google.com/search?client=navclient-auto&features=Rank:&q=info:";
  21. $GoogleURL = $StartURL.$domain. '&ch='.HashURL($domain);
  22. $fcontents = file_get_contents("$GoogleURL");
  23. $pagerank = substr($fcontents,9);
  24. if (!$pagerank) return "0";else return $pagerank;
  25. }
复制代码

说明: PR有时查询有点慢,很多的PR查询站都做了各种缓存的,一般情况下,PR值不会改变,除非谷歌PR更新。



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。