|
|
View Full Version : Google PageRank Checksum Algorithm
Unregistered 10-18-2005, 10:37 AM Hi,
I have the exact same problem. You fond a workaroung ?
This is the problem..
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.
Im still trying to figure out a workaround for it..
Bob Russell 10-18-2005, 11:12 AM Just curious... is this still relevant or useful? (I was under the impression it is no longer updated or accurate on the Google side of things, but I don't know anything about it so don't take my impression as fact.)
I am almost done with the vb.net version. It's a big pain in the butt though.
ovidiuweb 01-19-2006, 09:31 AM Does somebody know how is calculated the $ch on this website http://www.pagerankprediction.com? They say that they predict the pagerank. Do you know how they do that?
Dieter Werner 02-17-2006, 09:46 AM Is there a Perl version of this available?
Thanks!
Yes, there is one ...
See: http://www.mobileread.com/forums/showpost.php?p=25525&postcount=6
medivh 03-04-2006, 08:30 PM Hi,
I wonder if anyone found a solution to the PR calculation not working on big endian systems? i.e. a script code that works with 64 bit integers? would be glad if someone could help... ;-)
--chris
chemoul 03-07-2006, 10:31 PM Hi,
I have a strange problem, where I use a php script (the one in this thread) to check pagerank. It works on one of my servers, but on the other one I get the "forbidden" error from Google.
Any idea why?
Steve
chemoul 03-08-2006, 12:43 AM Also the checksums on both servers are different for one and the same domain. I have no idea why? :blink:
Jippi 03-18-2006, 08:31 PM What was the conculusion... was there a working php script ? that works on php 5.1.2 also ? been googling like crazy for the last days to find one, but none of them return the right ch's :(
alexanderg 03-28-2006, 10:35 AM Google PageRank Checksum Algorithm(GoogleToolbar 3.0.125.1-big)
http://www.gamesaga.net/pagerank.php
C and PHP implelation
http://ww.gamesaga.net/pr.zip
http://ww.gamesaga.net/pr.tar.gz
Url http://www.gamesaga.net/pagerank.php is not valid and site http://www.gamesaga.net it seems does not contain information about PageRank anymore.
Do you know another resources with description of the new GooglePR algorithm version 3+ ?
Gagget 04-03-2006, 11:59 AM Hello @all
At the beginnng i have to say that i'm a german guy and my english is not very well. In the last Days i worked on some changes for a Friend and his Installation of phpLinkDirectory (The Pagerank script is included there).
After I uploaded it on the Server (64bit Linux PHP 5.0.5), it appears exact the same problem with the different or false Google checksum ($sh). So I think NOT that PHP 5.1.2 is the Problem. I think the "Unregistred" is right. The maximum signed integer value for 64 bit systems is the Problem.
Tonight, after several Hours of work, I found a Solution, but i couldnt test it on a Server with PHP 5.1.2 and 64bit System cause i didn't have one.
I tested it on :
Win32 PHP 4.3.x
Win32 PHP 5.0.0
Linux64 PHP 5.0.5
Linux32 PHP 5.0.5
and now it works on all servers. :)
Additional, i coded the get_url() function, which was used to connect Google, out and replaced it with some fsockopen action. Cause on some Servers functions like get_url() are disabled for security reasons.
My Question is, if someone could test my changes on a 64bit PHP5.1.2 Machine and have a look to my code before i will publish the Code Changes here. (PM with E-Mail is enough) Cause i know i am not the best coder in Bit Operations(long long time ago) and i don't want to publish buggy PHP code here.
@Moderators: If my English is to bad, feel free to edit the post. I think it will be easier for others to read.
Hi. Im very interested in an Pagerank Check Script in PHP for 64Bit systems.
All i could find was functions or classes for 32bit Systems.
Would be great if anyone have an idea.
by the way.. the checksum wich get created is on
32bit system: 1104488743
64bit system: -2627036557665167874
thats why i need a 64bit version ;)
jacki 04-16-2006, 05:17 AM I am looking for this algorithm but in c++. Can somebody help me?
CGSoftLabs 04-26-2006, 10:16 PM PHP Data Type Converting Bug.
<?php
//header("Content-Type: text/plain; charset=utf-8");
$n = -6288256054;
var_dump($n);
$a = intval($n);
var_dump($a);
$b = (int) $n;
var_dump($b);
settype($n,"int");
var_dump($n);
?>
============good==========
float(-6288256054)
int(-1993288758)
int(-1993288758)
int(-1993288758)
============bad=================
float(-6288256054)
int(-2147483648)
int(-2147483648)
int(-2147483648)
yes..this is the problem
I have a php script running on some server for getting pagerank;
After running fine for a while, few weeks ago it died; so I said..google changed the crc..but it wasn't like that; yesterday I started to read the forums in search of answers till I found this;
I looked deep inside the code to see what's really happens :)
First let's say that php installed on my server is PHP Version 4.3.10;
Well the problem lies inside mix($a,$b,$c) function; it's about Arithmetic Operators which can operate only with 32bit balues; so when we perform $a ^ (zeroFill($c,13)) we must be sure we have 32bit integers;
On 32bit OS's the conversion is done well from double (64bit numbers) to long (32 bit) before xoring; but on 64 you see what's happens especially with small negative numbers ..small than MIN_INT which is (-2147483648) aka 0x80000000;
so if we have a double (-6288256054) which is small than MIN_INT on 32OS will be truncated in a way..and on 64 it will return always MIN_INT; knowing this we can detect where it runs on 64 or 32 bit OS's :);
so quiqly I write a helper to fix our double integers;
function toInt32(& $x){
$z = hexdec(80000000);
$y = (int)$x;
// on 64bit OSs if $x is double, negative ,will return -$z in $y
// which means 32th bit set (the sign bit)
if($y==-$z&&$x<-$z){
$y = (int)((-1)*$x);// this is the hack, make it positive before
$y = (-1)*$y; // switch back the sign
//echo "int hack <br>";
}
$x = $y;
}
then apply this function right before xoring inside mix function...foreach line
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,13)));
function mix($a,$b,$c) {
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,13)));
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<8));
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,13)));
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,12)));
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<16));
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,5)));
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,3)));
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<10));
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,15)));
return array($a,$b,$c);
}
with this, now I have my script running again...on "supposed" 64bit host machine..(coz I don't know if this is true :crowngrin )
greatz
CG
http://cgsoftlabs.ro
truvahorse 06-01-2006, 07:37 AM This php pagerank script (http://www.dikkatitvar.com/pagerank.rar) works fine.
2 files and 1 directory in it.
index.php (calls pagerank.php)
pagerank.php (script code)
images (images directory)
Upload all files and run "index.php"
Now who can help me to convert "index.php" codes to html codes.
Becasue i want to call "pagerank.php" by a html code and and offer this little code to my visitors.
Regards,
Jippi 06-06-2006, 03:18 AM Your client does not have permission t<>o get URL /search?client=navclient-auto&ch=6-1392492760&features=Rank&q=info:http://www.guu.dk/ from t<>his server. (Client IP address: 82.103.133.192)
With that script
PHP 5.1.2 (cli) (built: Feb 15 2006 18:39:30)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5-beta1, Copyright (c) 2004-2005 eAccelerator, by eAccelerator
Jippi 06-06-2006, 03:25 AM I applied CGSoftLabs 's toInt32 patch, and now it works like a charm :D
may you post it please? i tried it but it didnt work. im running PHP Version 4.3.10
with apache 2.0 and suse 9.0 64bit.
if i use it on 32bit it works but when i try to use it on 64bit its says "forbidden". i.e for google.com it tries to open http://www.google.com/search?client=navclient-auto&ch=63482137592031422572&features=Rank&q=info:www.google.com
on 64bit
ontananza 06-11-2006, 07:16 PM I've already looking for a google checksum algorithm, i've found one:
Written and contributed by
Alex Stapleton,
Andy Doctorow,
Tarakan,
Bill Zeller,
Vijay "Cyberax" Bhatter
traB
header("Content-Type: text/plain; charset=utf-8");
define('GOOGLE_MAGIC', 0xE6359A60);
etc...
I've tested on local enviroment on windows (PHP 5), it works : :happy2:
but when i moved out to one linux server with php 4.3.9 it doesn't works :(
im not sure why is it...
someone could tell me why???
Gagget 06-15-2006, 09:12 AM Sorry, I have completly forgotten to post my code here. Itīs tested by some people now and it works very fine.
To make it easier to update existing scripts, i commented the changes.
/*
Written and contributed by
Alex Stapleton,
Andy Doctorow,
Tarakan,
Bill Zeller,
Vijay "Cyberax" Bhatter
traB
This code is released into the public domain
*/
define('GOOGLE_MAGIC', 0x00000000E6359A60); // CHANGED (64Bit)
//unsigned shift right
function zeroFill($a, $b)
{
$z = 0x0000000080000000; // CHANGED (64Bit)
$a = $a & 0x00000000FFFFFFFF; // ADDED (64Bit)
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x0000000040000000; // CHANGED (64Bit)
$a = ($a>>($b-1));
}
else
{ $a = ($a>>$b);
}
return $a;
}
function mix($a,$b,$c) {
$a = $a & 0x00000000FFFFFFFF; // ADDED (64Bit)
$b = $b & 0x00000000FFFFFFFF; // ADDED (64Bit)
$c = $c & 0x00000000FFFFFFFF; // ADDED (64Bit)
$a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= (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 = 0x000000009E3779B9; // CHANGED (64Bit)
$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 = mix($a,$b,$c);
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len) /* all the case statements fall through */
{
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]);
/* case 0: nothing left to add */
}
$mix = 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;
}
// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32
function c32to8bit($arr32) {
for($i=0;$i<count($arr32);$i++) {
for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
$arr8[$bitOrder]=$arr32[$i]&255;
$arr32[$i]=zeroFill($arr32[$i], 8);
}
}
return $arr8;
}
function GoogleCHNew($ch){
$ch=sprintf("%u", $ch);
$ch = ((($ch/7) << 2) | (((int)fmod($ch,13))&7));
$prbuf = array();
$prbuf[0] = $ch;
for($i = 1; $i < 20; $i++) {
$prbuf[$i] = $prbuf[$i-1]-9;
}
$ch = GoogleCH(c32to8bit($prbuf), 80);
return sprintf("%u", $ch);
}
function get_page_rank($url){
$url = preg_replace('/\?.*$/','?',$url);
$reqgr = "info:".$url;
$reqgre = "info:".urlencode($url);
$gch = GoogleCH(strord($reqgr));
$gch = "6".GoogleCHNew($gch);
$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{
// BEGIN CHANGES (fsockopen to request PR)
$fsock = fsockopen('toolbarqueries.google.com', 80, $errno, $errstr);
if ( !$fsock ){
return -1;
}
$base_get = "/search?client=navclient-auto&ch=".$gch."&ie=UTF-8&oe=UTF-8&features=Rank:FVN&q=".$reqgre;
fputs($fsock, "GET $base_get HTTP/1.1\r\n");
fputs($fsock, "HOST: toolbarqueries.google.com\r\n");
fputs($fsock, "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n");
fputs($fsock, "Connection: close\r\n\r\n");
while(!feof($fsock)){
$res['content'] .= fread($fsock, 1024);
}
fclose($fsock);
// END CHANGES (fsockopen to request PR)
if(preg_match('/Rank_.*?:.*?:(\d+)/i', $res['content'], $m)){
return $m[1];
}else{
return -1;
}
}
}
?>
alirezan 06-21-2006, 05:44 PM Hi guys,
I still can't get it to work. Has anybody got a working version? Can you post the code here so that we all can use it?
Thanks
Ali
ontananza 06-27-2006, 09:28 PM Hi there:
This is a working 64bit version of the google checksum algorithm.
Enjoy it :)
TO use it :
$checksum= new google_checksum();
$ch="6".$checksum->getGoogleChecksum('domain.com');
And the class:
<?PHP
/*
Written and contributed by
Alex Stapleton,
Andy Doctorow,
Tarakan,
Bill Zeller,
Vijay "Cyberax" Bhatter
traB
This code is released into the public domain
*/
define('GOOGLE_MAGIC', 0xE6359A60);
class google_checksum{
var $checksum;
function google_checksum(){
$this->checksum='';
}
//unsigned shift right
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 mixOld($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 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);
}
//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;
}
// calculates the google checksum
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) /* all the case statements fall through */
{
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]);
/* case 0: nothing left to add */
}
$mix = $this->mix($a,$b,$c);
/*-------------------------------------------- report the result */
return $mix[2];
}
// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32
function c32to8bit($arr32){
for($i=0;$i<count($arr32);$i++) {
for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
$arr8[$bitOrder]=$arr32[$i]&255;
$arr32[$i]=zeroFill($arr32[$i], 8);
}
}
return $arr8;
}
// gets the google checksum!
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;
}
// converts 64 bit 2 32 bit
function toInt32(& $x){
$z = hexdec(80000000);
$y = (int)$x;
// on 64bit OSs if $x is double, negative ,will return -$z in $y
// which means 32th bit set (the sign bit)
if($y==-$z&&$x<-$z){
$y = (int)((-1)*$x);// this is the hack, make it positive before
$y = (-1)*$y; // switch back the sign
//echo "int hack <br>";
}
$x = $y;
}
}
?>
dbase 07-26-2006, 02:52 AM I have read every post here, and my php skills are not what I thought they were. I have worked at getting a 32bit version working on my PHP4 box for several hours. Could someone please post the newest working version.
AboutSledge 08-16-2006, 11:56 AM Url http://www.gamesaga.net/pagerank.php is not valid and site http://www.gamesaga.net it seems does not contain information about PageRank anymore.
Do you know another resources with description of the new GooglePR algorithm version 3+ ?
http://home.zhiwei.li/pagerank/
Google Toolbar 5.0.x for IE (difficult)
Google Toolbar for Firefox (easy)
I tried the code below, but I also could not get it to work on my 64 bit server.
I added the lines
$url = "www.google.co.uk";
echo "PageRank of ".$url." is: ".get_page_rank($url);
to the end of the function, so it would get googles PR (just as a test)
but whenever it was run it gives a value of -1 which is that thing that happens when I use the code for a 32 bit machine.
Can anyone help me (all of us) on this? Maybe someone has got it working, if so can you please post the code here.
Thanks
Sorry, I have completly forgotten to post my code here. Itīs tested by some people now and it works very fine.
To make it easier to update existing scripts, i commented the changes.
/*
Written and contributed by
Alex Stapleton,
Andy Doctorow,
Tarakan,
Bill Zeller,
Vijay "Cyberax" Bhatter
traB
This code is released into the public domain
*/
define('GOOGLE_MAGIC', 0x00000000E6359A60); // CHANGED (64Bit)
//unsigned shift right
function zeroFill($a, $b)
{
$z = 0x0000000080000000; // CHANGED (64Bit)
$a = $a & 0x00000000FFFFFFFF; // ADDED (64Bit)
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x0000000040000000; // CHANGED (64Bit)
$a = ($a>>($b-1));
}
else
{ $a = ($a>>$b);
}
return $a;
}
function mix($a,$b,$c) {
$a = $a & 0x00000000FFFFFFFF; // ADDED (64Bit)
$b = $b & 0x00000000FFFFFFFF; // ADDED (64Bit)
$c = $c & 0x00000000FFFFFFFF; // ADDED (64Bit)
$a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= (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 = 0x000000009E3779B9; // CHANGED (64Bit)
$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 = mix($a,$b,$c);
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len) /* all the case statements fall through */
{
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]);
/* case 0: nothing left to add */
}
$mix = 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;
}
// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32
function c32to8bit($arr32) {
for($i=0;$i<count($arr32);$i++) {
for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
$arr8[$bitOrder]=$arr32[$i]&255;
$arr32[$i]=zeroFill($arr32[$i], 8);
}
}
return $arr8;
}
function GoogleCHNew($ch){
$ch=sprintf("%u", $ch);
$ch = ((($ch/7) << 2) | (((int)fmod($ch,13))&7));
$prbuf = array();
$prbuf[0] = $ch;
for($i = 1; $i < 20; $i++) {
$prbuf[$i] = $prbuf[$i-1]-9;
}
$ch = GoogleCH(c32to8bit($prbuf), 80);
return sprintf("%u", $ch);
}
function get_page_rank($url){
$url = preg_replace('/\?.*$/','?',$url);
$reqgr = "info:".$url;
$reqgre = "info:".urlencode($url);
$gch = GoogleCH(strord($reqgr));
$gch = "6".GoogleCHNew($gch);
$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{
// BEGIN CHANGES (fsockopen to request PR)
$fsock = fsockopen('toolbarqueries.google.com', 80, $errno, $errstr);
if ( !$fsock ){
return -1;
}
$base_get = "/search?client=navclient-auto&ch=".$gch."&ie=UTF-8&oe=UTF-8&features=Rank:FVN&q=".$reqgre;
fputs($fsock, "GET $base_get HTTP/1.1\r\n");
fputs($fsock, "HOST: toolbarqueries.google.com\r\n");
fputs($fsock, "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n");
fputs($fsock, "Connection: close\r\n\r\n");
while(!feof($fsock)){
$res['content'] .= fread($fsock, 1024);
}
fclose($fsock);
// END CHANGES (fsockopen to request PR)
if(preg_match('/Rank_.*?:.*?:(\d+)/i', $res['content'], $m)){
return $m[1];
}else{
return -1;
}
}
}
?>
OK i got it working now :D
Ok, I thought I had it working but some websites give an error. Can anyone help me with this?
Thanks
bonusrobber 09-08-2006, 08:58 AM I get
int(-6288256054)
int(-6288256054)
int(-6288256054)
int(-6288256054)
Host provider is bluehost and PHP 4.4.4 (cgi)
Linux 2.6.17-11_1.BHsmp #1 SMP Thu Aug 24 09:39:29 MDT 2006 x86_64 x86_64 x86_64 GNU/Linux
Not a single example here to fetch pr work there =(
Me
http://www.findmatch.org
100% Free dating & penpals service
PHP Data Type Converting Bug.
<?php
//header("Content-Type: text/plain; charset=utf-8");
$n = -6288256054;
var_dump($n);
$a = intval($n);
var_dump($a);
$b = (int) $n;
var_dump($b);
settype($n,"int");
var_dump($n);
?>
============good==========
float(-6288256054)
int(-1993288758)
int(-1993288758)
int(-1993288758)
============bad=================
float(-6288256054)
int(-2147483648)
int(-2147483648)
int(-2147483648)
I've tried all the scripts on here, and I appear to have a problem generating the ch correctly, which is apparently down to an issue with the way certain versions of PHP handle the bitwise operations. Any ideas on a fix?
I have documented my findings here: http://www.googlecommunity.com/about14098.html
My Server information:
Operating system CentOS Linux
Kernel version 2.6.8-022stab078.14-smp
Machine Type i686
Apache version 1.3.37 (Unix)
PERL version 5.8.7
PHP version 4.4.4
MySQL version 4.1.21-standard
cPanel Build 10.8.2-RELEASE 119
If you think you can resolve this problem, I will give you an account on my server to attempt a solution.
AboutSledge 09-20-2006, 11:33 PM I've tried all the scripts on here, and I appear to have a problem generating the ch correctly, which is apparently down to an issue with the way certain versions of PHP handle the bitwise operations. Any ideas on a fix?
I have documented my findings here: http://www.googlecommunity.com/about14098.html
My Server information:
Operating system CentOS Linux
Kernel version 2.6.8-022stab078.14-smp
Machine Type i686
Apache version 1.3.37 (Unix)
PERL version 5.8.7
PHP version 4.4.4
MySQL version 4.1.21-standard
cPanel Build 10.8.2-RELEASE 119
If you think you can resolve this problem, I will give you an account on my server to attempt a solution.
Maybe I can resolve it.
GTalk/MSN/E-Mail: anykai [at] gmail <dot> com
There is still no working solution for people with newer version of PHP...
AboutSledge 10-18-2006, 08:19 AM google toolbar 4.0.x checksum algo
Server-side scripting demo
http://pagerank.gamesaga.net/
PHP Server-side scripting source code
http://pagerank.gamesaga.net/pagerank.zip
source code for Python
http://pagerank.gamesaga.net/pagerank.txt
source code for C
http://pagerank.gamesaga.net/pagerank.c
2005-09-13 v0.1 first release
2005-10-21 v1.1 fix a bug for the final character
2006-09-21 v1.2 compatible with PHP 4.4/PHP 5.x
2006-09-29 v1.3 X86_64 CPU supported
Any suggestions and feedback is welcome.
ps:
this script works on hm2k's server which is i686 arch
In addition to this, i've released some background about this here:
http://www.hm2k.com/projects/pagerank/
Raja Amer Khan 11-26-2007, 01:20 PM Hello guys!
This script is awesome!
thank you..
Now i want some other help..
I want to save the pagerank in mysql, because i have lots of websites saved in mysql and i displayed sort option for other columns, but i cannot sort by page rank.
So is there any option so i could save pagerank function in my mysql or any other solution to make it sortable?
thank you for quick reply..
hacker 11-26-2007, 04:42 PM Why are people so interested in Google's PageRank value? It means ABSOLUTELY NOTHING with respect to a site's quality or content.
PageRank means one thing: Sites link to you. That's it, that's all it means.
Just because a site links to you, doesn't mean your site has any value at all. With the advent of "paid links" and "purchased traffic", the whole meaning of PageRank is diminished.
Frankly, I'm glad that Google has been considering getting rid of PageRank altogether anyway. The notion of backlinks used to have some meaning, but now (like all abuses of the system), it has been overrun by irrelevant, unrelated links.
SEO 2.0 is where everything is heading, and where it should have headed to begin with. Forget optimizing meta tags (note: I've written a tool to do exactly that (http://keywordtool.mobilepress.org/)), forget focusing on backlinks, paid traffic or affiliate programs.
The only way a site continues to be successful and thrive, is through its content. Quality content, brings quality users, who will either return, or link to your site as "authoritative" in its niche.
Or not.
But you have to keep focusing on it. Marketing your niche is a full-time job. You can't just throw a site out there with AdSense ads and walk away, and expect to just cash the checks every month. You need to constantly tweak, rewrite, add/modify, and encourage people to go to the site for the content you have on it.
SEO 2.0 is about organic page relevance. The search engines are getting smarter, and they're now able to analyze trends in the users and the traffic.
They no longer care how many backlinks you have (one of the sites I run has over 23k backlinks and is a PR7), they don't care what your meta tags say, they care what users are visiting your site, at what frequency, and how often they come back, and from what sites they're coming from.
Focus on content, because content is king.
Market your niche, and bring in users, and let those users advertise for you. This is no different than being in the real world selling products. You're selling your site to visitors. It is no different.
PageRank, while a neat way to say "My PR is bigger than your PR", means nothing, if you don't know how to turn that PR into something useful by marketing to those people who link to you, and marketing to the users who sit behind those backlink sites.
Some people use PR to determine how much they can ask for a link from their site. I think it was recently that Google penalized a lot of sites, including prominent ones, for selling text links.
JSWolf 11-26-2007, 08:20 PM I think this thread is just silly and has no real purpose.
Alexander Turcic 11-26-2007, 09:22 PM I think this thread is just silly and has no real purpose.
Jon, I think it used to have a purpose. If my memory serves me right, this was the first place the algorithm for querying the Google Pagerank was publicly revealed. From there on, all of today's pagerank checker tools emerged.
But I agree with you guys... Pagerank is a relict of the past (when Google was still a lab project).
If PageRank was pointless/worthless google wouldn't include it on their toolbar would they? *grin*
PageRank is a result of their algorithm, it's as much a part of Google as the serps. Created by Larry Page, one of the founders of Google. (hence the name? heh), it's not going anywhere.
However, in a way "hacker" is correct, pagerank is purely a webmaster tool.
All you need to really do is focus on your content, and backlinks.
Do NOT focus on PR, because it will get you nowhere fast.
Content is king - get that right, and the rest will follow.
Backlinks are key - why do you think google used to be called backrub? google is built around backlinks.
Enjoy!
Ohwada 02-10-2008, 04:48 AM sorry. double post. same as #292
Ohwada 02-10-2008, 04:54 AM Thank you for useful program. :)
I rewrite to PHP class.
and show green bar same as "Google Toolbar".
demonstration
http://linux.ohwada.jp/demo/google_pagerank/
source code
https://sourceforge.jp/projects/xoops4u/files/?release_id=29337#29337
AboutSledge 08-20-2008, 03:53 AM http://home.zhiwei.li/pagerank/
(in PHP and Python)
Algorithm for Firefox is easy, for IE is terrible
pigreek 10-20-2008, 07:44 AM I tried to get the correct hash number in java but I use an old program that does not work with long url. (http://www.webmasterwords.com/pagerank-checksum-in-java)
Have anyone a java implementation of hash calculus?
Thnaks
hacker 10-20-2008, 09:40 AM I tried to get the correct hash number in java but I use an old program that does not work with long url. (http://www.webmasterwords.com/pagerank-checksum-in-java)
Have anyone a java implementation of hash calculus?
Thnaks Forget PageRank; focusing on it is pointless and it has become an irrelevant measure of ranking your website's "quality" in current times. It served its purpose when it was created, but that purpose is no longer needed now.
Move past it now, everyone else has.
|