Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Sprawdzanie PR strony
Forum PHP.pl > Forum > PHP
crackcomm
Witam, probuje sprawdzić pagerank strony w google z poziomu skrypt, mam coś takiego :
Kod
<?php

define('GOOGLE_MAGIC', 0x00000000E6359A60); // CHANGED (64Bit)

class google_pr
{

var $checksum;

function google_pr(){
    $this->checksum='';
}

function zeroFill($a, $b){
    $z = hexdec(80000000);
    if ($z & $a)
    {
        $a = ($a>>1);
        $a &= (~$z);
        $a |= 0x40000000;
        $a = ($a>>($b-1));
    } else {
        $a = ($a>>$b);
    }
    return $a;
}


function mix($a,$b,$c) {
    $a -= $b; $a -= $c; $this->toInt32($a); $a = (int)($a ^ ($this->zeroFill($c,13)));
    $b -= $c; $b -= $a; $this->toInt32($b); $b = (int)($b ^ ($a<<8));
    $c -= $a; $c -= $b; $this->toInt32($c); $c = (int)($c ^ ($this->zeroFill($b,13)));
    $a -= $b; $a -= $c; $this->toInt32($a); $a = (int)($a ^ ($this->zeroFill($c,12)));
    $b -= $c; $b -= $a; $this->toInt32($b); $b = (int)($b ^ ($a<<16));
    $c -= $a; $c -= $b; $this->toInt32($c); $c = (int)($c ^ ($this->zeroFill($b,5)));
    $a -= $b; $a -= $c; $this->toInt32($a); $a = (int)($a ^ ($this->zeroFill($c,3)));
    $b -= $c; $b -= $a; $this->toInt32($b); $b = (int)($b ^ ($a<<10));
    $c -= $a; $c -= $b; $this->toInt32($c); $c = (int)($c ^ ($this->zeroFill($b,15)));
    return array($a,$b,$c);
}

function strord($string) {
    for($i=0;$i<strlen($string);$i++) {
        $result[$i] = ord($string{$i});
    }
    return $result;
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
    if(is_null($length)) {
        $length = sizeof($url);
    }
    $a = $b = 0x9E3779B9;
    $c = $init;
    $k = 0;
    $len = $length;
    while($len >= 12) {
        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
        $mix = $this->mix($a,$b,$c);
        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
        $k += 12;
        $len -= 12;
    }

    $c += $length;
    switch($len)
    {
        case 11: $c+=($url[$k+10]<<24);
        case 10: $c+=($url[$k+9]<<16);
        case 9 : $c+=($url[$k+8]<<8);
        case 8 : $b+=($url[$k+7]<<24);
        case 7 : $b+=($url[$k+6]<<16);
        case 6 : $b+=($url[$k+5]<<8);
        case 5 : $b+=($url[$k+4]);
        case 4 : $a+=($url[$k+3]<<24);
        case 3 : $a+=($url[$k+2]<<16);
        case 2 : $a+=($url[$k+1]<<8);
        case 1 : $a+=($url[$k+0]);
    }
    $mix = $this->mix($a,$b,$c);

    return $mix[2];
}


function getGoogleChecksum($url) {
    $url="info:"."http://".str_replace('http://','',$url);
    $tmp_ch=$this->strord($url);
    $this->checksum=sprintf("%u", $this->GoogleCH($tmp_ch));
    return $this->checksum;
}

function toInt32(& $x) {
    $z = hexdec(80000000);
    $y = (int)$x;
    if($y==-$z&&$x<-$z){
        $y = (int)((-1)*$x);
        $y = (-1)*$y;
    }
    $x = $y;
}

function get_page_rank($url){
  
    $reqgr = "info:".$url;
    $reqgre = "info:".urlencode($url);
    $gch="6".$this->getGoogleChecksum($url);
    $patern = '/^http:/';
    $patern2 = '/^http:\/\/.*google\..*\/(search|images|groups|news).*/';
    $patern3 = '/^http:\/\/localhost.*/';
    $patern4 = '/^http:\/\/(127\.|10\.|172\.16|192\.168).*/'; //local ip
    if(!preg_match($patern, $url) || preg_match($patern2, $url) ||
       preg_match($patern3, $url) || preg_match($patern4, $url)){
           return -1;
    }
    else
    {

   $website = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=".$gch."&ie=UTF-8&oe=UTF-8&features=Rank&q=".$reqgre;
   if(!$ch = curl_init($website)) {
       return 'Count not connect to google.com';
   }
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; GoogleToolbar 3.0.114-big; Windows XP 5.1)');
   curl_setopt ($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_TIMEOUT, 20);
   $res['content'] = curl_exec($ch);
   curl_close ($ch);
  
        if(preg_match('/Rank_.*?:.*?:(\d+)/i', $res['content'], $m))
        {
              return $m[1];
        }
        else
        {
            return 0;
        }
    }
}
}

?>


Wywoluje to tak :
$pr = new google_pr;
echo $pr->get_page_rank('url.pl');
skrypt pokazuje pr "-1" lub 0 - nawet gdy jest np 5moze macie inne skrypty lub wskazania ?
tyranka
mozna by sie zastanowic czy 0 i 1 to nie prawda i falsz, udalo sie i nie
oscar17
Ja używam google_pagerank.class z http://code.google.com/p/popstats/, ale miałem też kiedyś inną klasę z http://www.phpclasses.org. Obie działały bezproblemowo - tylko pamiętaj że na raz możesz maks około 1000 zapytań do googla wysłać, później zawsze będzie zwracał 0 lub -1 (zależy co będziesz miał ustawione) - bo google nie lubi takich automatów i wyskoczy captcha i automat nie otrzyma wyników. Musisz pamiętać że jest kilka opcji wyskoczenia takiego czegoś (0 lub -1):
- strona nie ma jeszcze PR
- strona ma PR = 0
- tymczasowy ban od googla - czyli captcha
- podałeś błędny adres i nie można pobrać dla takiego PR...
crackcomm
ok pogrzebie w tym smile.gif
EDIT:
dzięki za te linki już działa
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-2025 Invision Power Services, Inc.