Google Community Chat
 
PageRank Lookup PHP Script - Error 403

You're visiting Google Community as a guest.
In order to post, you'll need to register and log in.



(If you were registered and logged in, these advertisements wouldn't be here)
Post new topic   Reply to topic    Google Community Forum Index // Google Search Engine Forum
   
Author Message
hm2k
Noogle
Noogle


Joined: 14 Sep 2006

274.00 GC$

Items

PostPosted: Thu Sep 14, 2006 7:58 am    Post subject: PageRank Lookup PHP Script - Error 403 Reply with quote
I have the php script that used to be on this site, but I modified it a little. The site says that there are some problems on certain servers I was wondering what that was down to.

For some reason when I use the script I appear to get the a 403 error from google, however the ch that is generated seems to be incorrect compaired to the one generated by the pagerank in the toolbar.

here is the code I am using:
Code:
<?php
//PageRank Lookup v0.2
//original: http://www.googlecommunity.com/s/google-pagerank.php

$googlehost="toolbarqueries.google.com";

define('GOOGLE_MAGIC', 0xE6359A60);

//unsigned shift right
function zeroFill($a, $b)
{
    $z = hexdec(80000000); //echo $z;
        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 ^= (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 = 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 = 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); //echo $mix[0];
    //report 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;

}

//http://www.example.com/ == 6540747202

function getch($url) {
    return "6" . GoogleCH(strord("info:" . $url));
}

function getpr($url) {
    global $googlehost;
    $ch = getch($url);
    $fp = fsockopen($googlehost, 80, $errno, $errstr, 30);
    if ($fp) {
       $out = "GET /search?client=navclient-auto&ch=$ch&features=Rank&q=info:$url HTTP/1.1\r\n";
       echo "<pre>$out</pre>\n";
       $out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6\r\n";
       $out .= "Host: $googlehost\r\n";
       $out .= "Connection: Close\r\n\r\n";
   
       fwrite($fp, $out);
      
       //$pagerank = substr(fgets($fp, 128), 4);
       //echo $pagerank;
       while (!feof($fp)) {
        $data = fgets($fp, 128);
        echo $data;
        $pos = strpos($data, "Rank_");
        if($pos === false){} else{
            $pagerank = substr($data, $pos + 9);
            return $pagerank;
        }
       }
       //else { echo "$errstr ($errno)<br />\n"; }
       fclose($fp);
    } //echo "ch: 6".$ch;
}

function pagerank($url) {
    $pr=str_replace("\n","",getpr($url));
    $prpos=40*$pr/10;
    $prneg=40-$prpos;
    $pagerank="PageRank: $pr/10";
    return '<a href="'.$url.'" title="'.$pagerank.'"><img src="http://www.google.com/images/pos.gif" width='.$prpos.' height=4 border=0 alt="'.$pagerank.'"><img src="http://www.google.com/images/neg.gif" width='.$prneg.' height=4 border=0 alt="'.$pagerank.'"></a>';
}

/*
if ((!$_POST) && (!$_GET)) { echo '<form action="" method="post"><input name="url" type="text"><input type="submit" name="Submit" value="Submit"></form>'; }
else {
   

    if (isset($_REQUEST["url"])) {
            $url=$_REQUEST["url"];
            if (!preg_match("/^(http:\/\/)?([^\/]+)/i", $url)) { die; }
        }
   
    $url="http://www.example.com/";
    header("Content-Type: text/plain; charset=utf-8"); echo 'PageRank: '.getpr($url);
    echo pagerank($url);
}
*/
if (isset($_GET['url'])) { echo pagerank($_GET['url']); }

//echo file_get_contents("http://www.google.com/search?client=navclient-auto&ch=6-242005025&features=Rank&q=info:http%3A//www.hm2k.org/");

?>


Here is the error i'm getting:
Code:

GET /search?client=navclient-auto&ch=6-820446282&features=Rank&q=info:http://www.hm2k.org/ HTTP/1.1

HTTP/1.1 403 Forbidden
Content-Type: text/html
Server: GWS/2.1
Content-Length: 4378
Date: Thu, 14 Sep 2006 15:56:10 GMT

<>
Google   
Error
 

Forbidden

Your client does not have permission to get URL /search?client=navclient-auto&ch=6-820446282&features=Rank&q=info:http://www.hm2k.org/ from this server.  (Client IP address: 87.117.209.202)


Please see Google's Terms of Service posted at http://www.google.com/terms_of_service.html


If you believe that you have received this response in error, please report
your problem. However, please make sure to take a look at our Terms of
Service (http://www.google.com/terms_of_service.html). In your email,
please send us the entire code displayed below. Please also
send us any information you may know about how you are performing your
Google searches-- for example, "I'm using the Opera browser on Linux to
do searches from home. My Internet access is through a dial-up account
I have with the FooCorp ISP." or "I'm using the Konqueror browser on
Linux to search from my job at myFoo.com. My machine's IP address is
10.20.30.40, but all of myFoo's web traffic goes through some kind of
proxy server whose IP address is 10.11.12.13." (If you don't know any
information like this, that's OK. But this kind of information can help
us track down problems, so please tell us what you can.)

We will
use all this information to diagnose the problem, and we'll hopefully
have you back up and searching with Google again quickly!


Please note that although we read all the email we receive, we are
not always able to send a personal response to each and every email. So
don't despair if you don't hear back from us!


Also note that if you do not send us the entire code below, we will not be able to help you.

Best wishes,
The Google Team

/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/

XRgYxRvnLFnOtyQHUQIeR9JvN-C47je95tbLnwL6QujynxBHq

Fi8mp50IEFPBYBOqTYt8kChTQkF1LaiTXGm16rl0eGfZX3VQB

53ZpwDZCBmUdewM0e_He4a9VGDG9SNY64XfS0kAfNP5oSY0QF

34OJuKT0b9EA-ASEfCurIHSB_mgDVBrfgGp-k-d24B1CW2kjg

txPBjCzOx91_Ku4pBiaUKzoBB0ffqTQZGFcc7iMm9-8lzLqPw

MHCLff644vA6t1Hnhh4PgzzJ3ND8V7gMd6Z_gYsTRk38pPlwb

cfDJ_NrzpNDX9Zua0iC42vZjXZNybHowyjSLw47wZMgmZapyZ

Ukyih_hXYB_skRdbSmO9J3SvjmJPx8lwhwG1S-DAEUuj3ZmQM

A3ylAP72l3VQ4igjp0INhxhgdC2wP1LDjfAP2syS8Jsl4YLA0

U0V207kgAHRcvOMkYprb1LWPV6k1IJlPfStkefGymMHtkM_Wi

rcB8IgGpMO3aLoMgHUNHl8V3wcsPJqyJHPG--MB3aMmxJbfwV

ZooHGDVnhmnWhOD-VYq0-uoevzfHoD8MgHcp5BI2MJtrxfY9Z

DUEi

+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+/+

PageRank: /10PageRank: /10


Does anyone know why i'm getting this error, and how I fix it.

If I use the REAL ch generated by the toolbar, I can retreive the information correctly.

Also I believe this script works on some servers, just not others, does anyone know what it is down to?

There is limited explanation about this so i'd like to find out more.

Thanks!
Back to top
View user's profile Send private message
hm2k
Noogle
Noogle


Joined: 14 Sep 2006

274.00 GC$

Items

PostPosted: Thu Sep 14, 2006 8:52 am    Post subject: Reply with quote
After looking at the following link:
http://66.249.93.104/search?q=cache:ybmkN618Fa8J:www.googleboard.com/about5786-0.html+%2Bpagerank+%2Bphp+%2B403+%2BForbidden+%2Bfix&hl=en&gl=uk&ct=clnk&cd=4&client=firefox-a

It seems the problem is down to the way the ch is generated by certain versions of PHP, and the way they handle bitwise operations.

Does anyone have any clue how to fix such a problem other than to use another scripting language to generate the ch (such as perl).
Back to top
View user's profile Send private message
hm2k
Noogle
Noogle


Joined: 14 Sep 2006

274.00 GC$

Items

PostPosted: Thu Sep 14, 2006 9:34 am    Post subject: Reply with quote
I found more information about this script and this issue here: http://www.mobileread.com/forums/showthread.php?t=1670

It is meant to be fixed, however it clearly isn't.

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.
Back to top
View user's profile Send private message
Sponsored Links
Posted: 7 Jan 2009 12:36 pm    Post subject: Advertisements
Back to top
Post new topic   Reply to topic    Google Community Forum Index // Google Search Engine Forum All times are GMT - 8 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Host your free forums with Invision Plus.net forum web hosting with your own subdomain.

alexisBlue v1.2 // Theme Created By: Andrew Charron // Icons in Part By: Travis Carden

© 2005-2006 Google Community

Powered by phpBB

Privacy Policy | Contact Us

Powered by Google Search blog

This website is not affiliated in any way with Google, Inc.
Google™ is a registered trademark of Google, Inc.