Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: pagerank
Forum PHP.pl > Forum > Gotowe rozwiązania > Szukam
Guest
weźmy na przyklad taką stronę:
http://pr.blogflux.com/pr3.php?s=http://www.wp.pl
efekt: PR 7/10

i teraz pytanie: jak wygląda skrypt w pr3.php?
nospor
Przenosze na gotowe skrypty
dyktek
np tak:

  1. <?php
  2.  
  3. define('GOOGLE_MAGIC', 0xE6359A60);
  4.  
  5.  
  6. function zeroFill($a, $b)
  7. {
  8. $z = hexdec(80000000);
  9. if ($z & $a)
  10. {
  11. $a = ($a>>1);
  12. $a &= (~$z);
  13. $a |= 0x40000000;
  14. $a = ($a>>($b-1));
  15. }
  16. else
  17. {
  18. $a = ($a>>$b);
  19. }
  20. return $a;
  21. }
  22.  
  23. function mix($a,$b,$c) {
  24. $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  25. $b -= $c; $b -= $a; $b ^= ($a<<8);
  26. $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  27. $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  28. $b -= $c; $b -= $a; $b ^= ($a<<16);
  29. $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  30. $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));  
  31. $b -= $c; $b -= $a; $b ^= ($a<<10);
  32. $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  33.  
  34. return array($a,$b,$c);
  35. }
  36.  
  37. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  38. if(is_null($length)) {
  39. $length = sizeof($url);
  40. }
  41. $a = $b = 0x9E3779B9;
  42. $c = $init;
  43. $k = 0;
  44. $len = $length;
  45. while($len >= 12) {
  46. $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  47. $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  48. $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  49. $mix = mix($a,$b,$c);
  50. $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  51. $k += 12;
  52. $len -= 12;
  53. }
  54.  
  55. $c += $length;
  56. switch($len) /* all the case statements fall through */
  57. {
  58. case 11: $c+=($url[$k+10]<<24);
  59. case 10: $c+=($url[$k+9]<<16);
  60. case 9 : $c+=($url[$k+8]<<8);
  61. /* the first byte of c is reserved for the length */
  62. case 8 : $b+=($url[$k+7]<<24);
  63. case 7 : $b+=($url[$k+6]<<16);
  64. case 6 : $b+=($url[$k+5]<<8);
  65. case 5 : $b+=($url[$k+4]);
  66. case 4 : $a+=($url[$k+3]<<24);
  67. case 3 : $a+=($url[$k+2]<<16);
  68. case 2 : $a+=($url[$k+1]<<8);
  69. case 1 : $a+=($url[$k+0]);
  70.  /* case 0: nothing left to add */
  71. }
  72. $mix = mix($a,$b,$c);
  73. /*-------------------------------------------- report the result */
  74. return $mix[2];
  75. }
  76.  
  77. //converts a string into an array of integers containing the numeric value of the 
    char
  78. function strord($string) {
  79. for($i=0;$i<strlen($string);$i++) {
  80. $result[$i] = ord($string{$i});
  81. }
  82. return $result;
  83. }
  84.  
  85. function getrank($url) {
  86. $url = 'info:'.$url;
  87. $ch = GoogleCH(strord($url));
  88. $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
  89. $data = file($file);
  90. $rankarray = explode (':', $data[2]);
  91. $rank = $rankarray[2];
  92. return $rank;
  93. }
  94.  
  95. $pr = "".getrank($_REQUEST['url'])."";
  96.  
  97. echo"$pr";
  98.  
  99. ?> 
karawan
tylko, że po wywyłaniu takiego skryptu dostaniemy:
Kod
Warning: file(http://www.google.com/search?client=navclient-auto&ch=665609398&features=Rank&q=info:www.onet.pl): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /PR/pgr.php on line 90

skrypt ten od jakiegoś czasu już nie działa blink.gif

Może zna ktoś działający skrypt smile.gif
Vogel
na boga. google i po chwili mialem dzialajacy:

  1. <html>
  2. <body style="font-family:verdana;font-size:13px">
  3. <?php
  4. /* 
  5. This code is released unto the public domain 
  6.  
  7. Raistlin Majere euclide@email.it 
  8.  
  9. */
  10. define('GOOGLE_MAGIC', 0xE6359A60);
  11.  
  12. //unsigned shift right
  13. function zeroFill($a, $b)
  14. {
  15. $z = hexdec(80000000);
  16. if ($z & $a)
  17. {
  18. $a = ($a>>1);
  19. $a &= (~$z);
  20. $a |= 0x40000000;
  21. $a = ($a>>($b-1));
  22. }
  23. else
  24. {
  25. $a = ($a>>$b);
  26. }
  27. return $a;
  28. }
  29.  
  30.  
  31. function mix($a,$b,$c) {
  32. $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  33. $b -= $c; $b -= $a; $b ^= ($a<<8);
  34. $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  35. $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  36. $b -= $c; $b -= $a; $b ^= ($a<<16);
  37. $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  38. $a -= $b; $a -= $c; $a ^= (zeroFill($c,3)); 
  39. $b -= $c; $b -= $a; $b ^= ($a<<10);
  40. $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  41.  
  42. return array($a,$b,$c);
  43. }
  44.  
  45. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  46. if(is_null($length)) {
  47. $length = sizeof($url);
  48. }
  49. $a = $b = 0x9E3779B9;
  50. $c = $init;
  51. $k = 0;
  52. $len = $length;
  53. while($len >= 12) {
  54. $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  55. $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  56. $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  57. $mix = mix($a,$b,$c);
  58. $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  59. $k += 12;
  60. $len -= 12;
  61. }
  62.  
  63. $c += $length;
  64. switch($len) /* all the case statements fall through */
  65. {
  66. case 11: $c+=($url[$k+10]<<24);
  67. case 10: $c+=($url[$k+9]<<16);
  68. case 9 : $c+=($url[$k+8]<<8);
  69. /* the first byte of c is reserved for the length */
  70. case 8 : $b+=($url[$k+7]<<24);
  71. case 7 : $b+=($url[$k+6]<<16);
  72. case 6 : $b+=($url[$k+5]<<8);
  73. case 5 : $b+=($url[$k+4]);
  74. case 4 : $a+=($url[$k+3]<<24);
  75. case 3 : $a+=($url[$k+2]<<16);
  76. case 2 : $a+=($url[$k+1]<<8);
  77. case 1 : $a+=($url[$k+0]);
  78. /* case 0: nothing left to add */
  79. }
  80. $mix = mix($a,$b,$c);
  81. /*-------------------------------------------- report the result */
  82. return $mix[2];
  83. }
  84.  
  85. //converts a string into an array of integers containing the numeric value of the 
    char
  86. function strord($string) {
  87. for($i=0;$i<strlen($string);$i++) {
  88. $result[$i] = ord($string{$i});
  89. }
  90. return $result;
  91. }
  92.  
  93. function get_pr($url) {
  94. $result=array("",-1);
  95.  
  96. if (($url.""!="")&&($url.""!="http://")):
  97. // check for protocol 
  98. if (substr(strtolower($url),0,7)!="http://"):
  99. $url="http://".$url;
  100. endif;
  101.  
  102. $url="info:".$url;
  103. $checksum=GoogleCH(strord($url));
  104. $google_url=sprintf("http://www.google.com/search?client=navclient-auto&ch=6%u&features=Rank&q=".$url,$checksum); // url to get from google 
  105.  
  106. $contents="";
  107. // let's get ranking 
  108. // this way could cause problems because the Browser Useragent is not set... 
  109. if ($handle=fopen($google_url,"rb")):
  110. while(true):
  111. $data=fread($handle,8192);
  112. if (strlen($data)==0):
  113. break;
  114. endif;
  115. $contents.=$data;
  116. endwhile;
  117. fclose($handle);
  118. else:
  119. $contents="Connection unavailable";
  120. endif;
  121.  
  122. $result[0]=$contents;
  123. // Rank_1:1:0 = 0 
  124. // Rank_1:1:5 = 5 
  125. // Rank_1:1:9 = 9 
  126. // Rank_1:2:10 = 10 etc 
  127. $p=explode(":",$contents);
  128. if (isset($p[2])):
  129. $result[1]=$p[2];
  130. endif;
  131. endif;
  132.  
  133. return $result;
  134. }
  135.  
  136. // GET IT ! 
  137. $pr=get_pr($_GET["url"]);
  138. $output=$pr[0];
  139. $pagerank=$pr[1];
  140. ?>
  141. <br>
  142. <form method="get" action="?r=<?=time()?>">
  143. <center>
  144. <table style="font-family:verdana;font-size:13px">
  145. <tr>
  146. <td valign="top"><b>Url</b></td>
  147. <td valign="top"><?=$_GET['url']?></td>
  148. </tr>
  149. <tr>
  150. <td valign="top"><b>Page<br>Rank</b></td>
  151. <td valign="top" style="color:red"><b><?=$pagerank?></b></td>
  152. </tr>
  153. <tr>
  154. <td valign="top"><b>Google<br>output</b></td>
  155. <td valign="top"><div style="overflow:auto;width:250px;height:150px;background-color:#eeeeee;border:1px solid #aaaaaa"><?=$output?></div></td>
  156. </tr>
  157. </table>
  158.  
  159. <br>
  160.  
  161. <input type="text" name="url" size="80" value="<?=isset($_GET['url'])?$_GET['url']:"http://"?>"><br>
  162. <input type="submit">
  163.  
  164. </center>
  165. </form>
  166. </body>
  167. </html>
Gość_kaktus
odpowiedz serwera google podobna:
Kod
Warning: fopen(http://www.google.com/search?client=navclient-auto&ch=63235867597&features=Rank&q=info:http://www.bibelot.pl): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /pgr1.php on line 109

bo to ten sam skrypt
Vogel
tak patrze na ten twoj "blad" i widze ze nie skrypt jest zly ale twoj serwer ma wylaczone allow_url_fopen
Gość_kaktus
Właśnie nie, sprawdziłem za pomocą phpinfo() i wartość allow_url_fopen jest "on", a poza tym wklejając to co wygenerował skrypt, np:
Kod
http://www.google.com/search?client=navclient-auto&ch=63235867597&features=Rank&q=info:http://www.bibelot.pl

do paska przeglądarki (ie, firefox)
pojawia sę się komunikat , że google error i że forbidden. wiem, że skrypt powyższy działał jeszcze dwa tygodnie temu, bo sam go używałem do szczytywania pageranku stron dodawanych do mojego katalogu.
Także nie wiem w czym bład dry.gif
karawan
Witam,
znalazłem dlaczego ten skrypt może nie działać na niektórych serwerach. Po prostu z jakich nie znanych przyczyn nie wszystkie serwery generują prawidłowa wartość $ch.( Google Community.com )
Dlaczego nie wiem
(np. u mnie skrypt na localhost śmiga a na serwerze home.pl już nie).
sf
@karawan: na Twoim miejscu bym zbadał dokładnie, w którym momencie się to sypie.. która linijka daje różne rezultaty i wtedy bym już wiedział winksmiley.jpg
karawan
No i właśnie skrypt przytoczony nie działa na niektórych serwerach poniżej daję skrypt który dziala:
jest to związane z 32 bitowa obsługą w funkcji mix,
dodatna zostana funkcja
function toInt32

  1. <?php
  2. $myWebSite = ($_POST['url']);
  3.  
  4. define('GMAG', 0xE6359A60);
  5.  
  6. //unsigned shift right
  7. function zeroFill($a, $b)
  8. {
  9. $z = hexdec(80000000);
  10. if ($z & $a)
  11. {
  12. $a = ($a>>1);
  13. $a &= (~$z);
  14. $a |= 0x40000000;
  15. $a = ($a>>($b-1));
  16. }
  17. else
  18. {
  19. $a = ($a>>$b);
  20. }
  21. return $a;
  22. }
  23.  
  24.  
  25. function toInt32(& $x){
  26. $z = hexdec(80000000);
  27. $y = (int)$x;
  28.  // on 64bit OSs if $x is double, negative ,will return -$z in $y
  29. // which means 32th bit set (the sign bit)
  30. if($y==-$z&&$x<-$z){
  31.  $y = (int)((-1)*$x);// this is the hack, make it positive before
  32. $y = (-1)*$y; // switch back the sign
  33.  //echo "int hack <br>";
  34.  }
  35.  $x = $y;
  36.  }
  37.  
  38.  
  39. function mix($a,$b,$c) {
  40.  $a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,13)));
  41. $b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<8));
  42. $c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,13)));
  43. $a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,12)));
  44. $b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<16));
  45. $c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,5)));
  46. $a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,3)));
  47. $b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<10));
  48. $c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,15)));
  49.  
  50. return array($a,$b,$c);
  51. }
  52.  
  53. function GCH($url, $length=null, $init=GMAG) {
  54. if(is_null($length)) {
  55. $length = sizeof($url);
  56. }
  57. $a = $b = 0x9E3779B9;
  58. $c = $init;
  59. $k = 0;
  60. $len = $length;
  61. while($len >= 12) {
  62. $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  63. $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  64. $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  65. $mix = mix($a,$b,$c);
  66. $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  67. $k += 12;
  68. $len -= 12;
  69. }
  70.  
  71. $c += $length;
  72. switch($len) /* all the case statements fall through */
  73. {
  74. case 11: $c+=($url[$k+10]<<24);
  75. case 10: $c+=($url[$k+9]<<16);
  76. case 9 : $c+=($url[$k+8]<<8);
  77. /* the first byte of c is reserved for the length */
  78. case 8 : $b+=($url[$k+7]<<24);
  79. case 7 : $b+=($url[$k+6]<<16);
  80. case 6 : $b+=($url[$k+5]<<8);
  81. case 5 : $b+=($url[$k+4]);
  82. case 4 : $a+=($url[$k+3]<<24);
  83. case 3 : $a+=($url[$k+2]<<16);
  84. case 2 : $a+=($url[$k+1]<<8);
  85. case 1 : $a+=($url[$k+0]);
  86. /* case 0: nothing left to add */
  87. }
  88. $mix = mix($a,$b,$c);
  89. /*-------------------------------------------- report the result */
  90. return $mix[2];
  91. }
  92.  
  93. //converts a string into an array of integers containing the numeric value of the 
    char
  94. function strord($string) {
  95. for($i=0;$i<strlen($string);$i++) {
  96. $result[$i] = ord($string{$i});
  97. }
  98. return $result;
  99. }
  100.  
  101. function getPR($_url) {
  102. $url = 'info:'.$_url;
  103. $ch = GCH(strord($url));
  104. $url='info:'.urlencode($_url);
  105. $pr = file("http://www.google.com/search?client=navclient-auto&ch=6$ch&ie=UTF-8&oe=UTF-8&features=Rank&q=$url");
  106.  
  107. $pr_str = implode("", $pr);
  108. return substr($pr_str,strrpos($pr_str, ":")+1);
  109. }
  110. ?>


wywołanie
  1. <?php
  2. getPR('www.strona.pl')
  3. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.