PHP skripta za PR
3 naročniki
3 naročniki
Spodnjo kodo bi rad uporabil za določanje PR v PHPLD.
Žal imam samo eno php gostovanje in zato ne morem stestirat, če je hosting provider kriv, da mi skripta vedno vrne -1 namesto dejanski PR.
Če ima kdo par minut bi bil zelo vesel če lahko sproba če njemu deluje.
<?php
/******************
* PageRankXor32 class created by MagicBeanDip
* PageRank class was created by others
* Look for updates at [url=http://v1.magicbeandip.com/mbd-file/PageRankReport.php]http://v1.magicbeandip.com/mbd-file/PageRankReport.php[/url]
* This code is released into the Public Domain
*
* Sample use:
* include('PageRankXor32.php');
* $oPR=new PageRankXor32();
* echo $oPR->getRank('http://www.amazon.com');
*
******************/
define('GOOGLE_MAGIC', 0xE6359A60);
// Use this class if your server is having problems with bitwise operations
class PageRankXor32 extends PageRank {
function xor32($a, $b) {
return $this->int32($a) ^ $this->int32($b);
}
//return least significant 32 bits
//works by telling unserialize to create an integer even though we provide a double value
function int32($x) {
return unserialize("i:$x;");
//return intval($x); // This line doesn't work on all servers.
}
function mix($a,$b,$c) {
$a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,13));
$b -= $c; $b -= $a; $b = $this->xor32($b,$a<<8);
$c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,13));
$a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,12));
$b -= $c; $b -= $a; $b = $this->xor32($b,$a<<16);
$c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,5));
$a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,3));
$b -= $c; $b -= $a; $b = $this->xor32($b,$a<<10);
$c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,15));
return array($a,$b,$c);
}
}
//This class should work on most servers
class PageRank {
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; $a ^= ($this->zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,15));
return array($a,$b,$c);
}
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);
/* the first byte of c is reserved for the length */
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);
/* report the result */
return $mix[2];
}
//converts a string into an array of integers containing the numeric value of the char
function strord($string) {
for($i=0;$i<strlen($string);$i++) {
$result[$i] = ord($string{$i});
}
return $result;
}
//returns -1 if no page rank was found
function getRank($url){
$ch = "6".$this->GoogleCH($this->strord("info:" . $url));
$pagerank=-1;
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)
\n";
} else {
$out = "GET /search?client=navclient-auto&ch=" . $ch . "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n" ;
$out .= "Host: www.google.com\r\n" ;
$out .= "Connection: Close\r\n\r\n" ;
fwrite($fp, $out);
while (!feof($fp)) {
$data = fgets($fp, 128);
$pos = strpos($data, "Rank_");
if($pos === false){
}else{
$pagerank = trim(substr($data, $pos + 9));
}
}
fclose($fp);
}
return $pagerank;
}
}
$oPR=new PageRankXor32();
echo $oPR->getRank('http://www.amazon.com');
?>
Hvala. :)
17 odgovorov
Ups. sem prehitro prebral, da naj zakometiram tisto vrstico z napako. Sem jo dal nazaj in sedaj vrne:
i:-4738698913; i:568102; i:4693521066; i:-1213234251520; i:1226708364973; i:-148598056; i:2439147803226; i:-299455989; i:2448685717220; i:-159870436064034816; i:159873960133356864; i:-4996023352369481; i:314755617647750518; i:-19360664262019458; i:290830646526609381; i:-7769812837921447936; i:8200924145173623050; i:-245971416350512; i:1.59650420913E+19;
Notice: unserialize() [function.unserialize]: Error at offset 0 of 20 bytes in /home/aonewebs/publichtml/test.php on line 26
i:-1001082617866077; i:141878519256407130; i:-256277150173715712; i:-8022407134063458228; i:-21662669540721; i:-7845933000913494394; i:1958591920696583; i:-353264047702322922; i:5824670236351201280; i:2.19360092006E+19;
Notice: unserialize() [function.unserialize]: Error at offset 0 of 20 bytes in /home/aonewebs/publichtml/test.php on line 26
i:-189594613907307896; i:-1589966789407301661; i:-23699326738413487; i:-7481981374385408292; i:1297280936926169088; i:6696699561334893562; i:-259119949905429; i:1.67921373282E+19;
Notice: unserialize() [function.unserialize]: Error at offset 0 of 20 bytes in /home/aonewebs/publichtml/test.php on line 26
i:-817473934410625; i:-1793278578169784270; i:-209273327209120000; i:-8570690493071620486; i:228852722242329; i:6695305186439757802; i:-2092501015865071; i:1.7141917243E+19;
Notice: unserialize() [function.unserialize]: Error at offset 0 of 19 bytes in /home/aonewebs/publichtml/test.php on line 26
i:1187156807688847360; i:-3061769387300983192; i:37098650106058752; i:-4785415771706429293; i:-387251577169201459; i:-846397627048590534; i:-2597399665987454976; i:-1.1667184169E+19;
Notice: unserialize() [function.unserialize]: Error at offset 0 of 20 bytes in /home/aonewebs/public_html/test.php on line 26
i:104907363878944; GET /search?client=navclient-auto&ch=6104907363878944&features=Rank&q=info:http://www.amazon.com HTTP/1.1 Host: www.google.com Connection: Close
Če tale zadnji:
www.google.com/search?client=navclient-auto&ch=6104907363878944&features=Rank&q=info:http://www.amazon.com
poženem v browserju mi isto vrže 403 error.
yep... "i:1.7141917243E+19;" je nepravilna vrednost za unserialize... probaj se namesto une unserialize vrstice uporabit uno intval() vrstico...
403 error ti vrne zato, ker je checksum narobe izracunan...
Ok zdaj mi ne javlja nobene napake ampak cecksum je pa še vedno očitno napačen. Ker PR Amazona izračuna -1
Zdaj namreč dobim tole:
i:-4738698913; i:568102; i:4693521066; i:-1213234251520; i:1226708364973; i:-148598056; i:2439147803226; i:-299455989; i:2448685717220; i:-159870436064034816; i:159873960133356864; i:-4996023352369481; i:314755617647750518; i:-19360664262019458; i:290830646526609381; i:-7769812837921447936; i:8200924145173623050; i:-245971416350512; i:1.59650420913E+19; i:-1001082617866077; i:-2341530335327896486; i:8307091117283255040; i:-4.68715785904E+18; i:-731948085752816; i:3790639304874349881; i:1144503707416784; i:-1.44757890856E+19; i:2213165483042603008; i:7906310557896807975; i:-219068954940848128; i:1.87785877324E+19; i:-997074749642871868; i:1963466192973674005; i:-6433619580275453952; i:-2190106730402362290; i:-146161392864768; i:1602371231700530358; i:267330387665327; i:-8581603125827317100; i:4338945060043561216; i:6001359495565860283; i:-660840458628134; i:1.3017788647E+19; i:-1465324106736976; i:-4839234282126189949; i:-5582708896114409472; i:-1.24613612697E+19; i:32243654310645460; i:1.35869282351E+19; i:-1148891047818016294; i:4.71047696114E+18; i:43433410056120320; i:-1.94426913566E+19; i:144626300497096;
GET /search?client=navclient-auto&ch=6-9223227410554278712&features=Rank&q=info:http://www.amazon.com HTTP/1.1 Host: www.google.com Connection: Close
-1
Hvala ker mi pomagaš.
Hjah, problem imas z integerji, tukaj si preberi malo vec o tem:
http://si.php.net/intval
sem nasel eno masino, na kateri se mi dogaja isto kot tebi :) workarounda ne vem...
lahko poskusis s temle:
http://si.php.net/manual/en/ref.bc.php
Moj server nima mojma o računanju. Pazi tole:
$exp1 = "1E5";
$exp2 = "2E4";
$ans1 = bcadd($exp1, $exp2, 3);
$ans2 = $exp1 + exp2;
echo("bcadd: $exp1 + $exp2 = $ans1");
echo("php: $exp1 + $exp2 = $ans2");
Vrne:
bcadd: 1E5 + 2E4 = 0.000 // bcadd ne podpira formata števil "1E5"
php: 1E5 + 2E4 = 100000 // moralo bi biti 120000
Ajaj, no zdaj vidim za malo denarja malo muzike -> hostmonster