use php to get google page rank
Since the google not give a API or interface to get the google page rank, we have to use google toolbar to get the PR. In order to use php to query toolbarqueries.google.com to the get PR, I did a search ,but most of the codes are too old and can’t use or not work well, at last i got following script works well.
use php to get google page rank
there is all the codes :
<?php function StrToNum($Str, $Check, $Magic) { $Int32Unit = 4294967296; // 2^32 $length = strlen($Str); for ($i = 0; $i < $length; $i++) { $Check *= $Magic; //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), // the result of converting to integer is undefined // refer to http://www.php.net/manual/en/language.types.integer.php if ($Check >= $Int32Unit) { $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit)); //if the check less than -2^31 $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check; } $Check += ord($Str{$i}); } return $Check; } //--> for google pagerank /* * Genearate a hash for a url */ function HashURL($String) { $Check1 = StrToNum($String, 0x1505, 0x21); $Check2 = StrToNum($String, 0, 0x1003F); $Check1 >>= 2; $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F); $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF); $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF); $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F ); $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 ); return ($T1 | $T2); } //--> for google pagerank /* * genearate a checksum for the hash string */ function CheckHash($Hashnum) { $CheckByte = 0; $Flag = 0; $HashStr = sprintf('%u', $Hashnum) ; $length = strlen($HashStr); for ($i = $length - 1; $i >= 0; $i --) { $Re = $HashStr{$i}; if (1 === ($Flag % 2)) { $Re += $Re; $Re = (int)($Re / 10) + ($Re % 10); } $CheckByte += $Re; $Flag ++; } $CheckByte %= 10; if (0 !== $CheckByte) { $CheckByte = 10 - $CheckByte; if (1 === ($Flag % 2) ) { if (1 === ($CheckByte % 2)) { $CheckByte += 9; } $CheckByte >>= 1; } } return '7'.$CheckByte.$HashStr; } //get google pagerank function getpagerank($url) { $query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0"; $data=file_get_contents_curl($query); //print_r($data); $pos = strpos($data, "Rank_"); if($pos === false){} else{ $pagerank = substr($data, $pos + 9); return $pagerank; } } function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } ?>
How to use it
Save the previous codes to a pr.php , the test.php
<?php include "pr.php"; $url='http://www.brightyoursite.com'; echo "$url PR is ". getPagerank($url) ; ?>
Source File
live demo
Update
Google have updated the pr search url,please change
$query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
to
$query="http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
.
, I'm a freelancer and available now,if need help just contact me without hesitation.
34 Responses to “use php to get google page rank”
Leave a Reply
-
Search for:
Categories
- apache (2)
- css xhtml (10)
- html5 (1)
- javascript (3)
- jquery (5)
- magento (3)
- mysql (1)
- php (1)
- SEO Friendly (6)
- Tools (3)
- w3c validation (4)
- Wordpress (4)


















This is a superb post use php to get google page rank.
But I was wondering how do I suscribe to the RSS feed?
if you need such a script just contact me
I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.
My cousin recommended this blog and she was totally right keep up the fantastic work!
I’m getting a 403 forbidden return when I run this (no pr output). Thoughts?
URL of the script: http://jtgraphic.net/test/pr.php?url=http://www.brightyoursite.com
I’m doing a print_r on data for now.
http://www.brightyoursite.com/demo/pr/test.php the demo it’s works fine in my project not sure whats wrong with you
This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!
Good fill someone in on and this enter helped me alot in my college assignement. Thanks you as your information.
It was very helpfull thank you so much for sharing. I will share it with my friends. Thanks
thanks!You made some good points there. I did a search on the topic and found most people will agree with your blog
[...] I found one that was fast, efficient and didn’t drain the server’s resources.I found it at brightyoursite.com but since I use CodeIgniter for most of my PHP work I decided to rewrite it to a class and clean it [...]
Thanks, you guys explained everthing I needed to know and very quicly 10 out of 10!
You wrote very interesting post i love your blog it contains very informative article i will share it with my friends.
it was very interesting to read.
I want to quote your post in my blog. It can?
And you et an account on Twitter?
[...] I found one that was fast, efficient and didn’t drain the server’s resources.I found it at brightyoursite.com but since I use CodeIgniter for most of my PHP work I decided to rewrite it to a class and clean it [...]
+1
yes you can but need point out the reference link
Thanks a lot!!!! working great!
Hey I found some fast pagerank tools, may be seo friends would like them.
seo41.com/pagerank-checker.php
seo41.com/internal-pagerank.php
one is bulk page rank checker that can check 1000 of pages PR with single click and another is internal PR checker to check pagerank of all internal pages on a website.
There is lot more helpful things for search engine optimization.
This script looks nice! I will check it. Does it works for subdomains too?
~;’ I am very thankful to this topic because it really gives useful information ~-.
This is very nice, excellent work and thank you for posting this!
nice work man
Heya i am for the primary time here. I came across this board and I in finding It truly helpful & it helped me out much. I’m hoping to offer one thing back and aid others such as you aided me.
some really good blog posts on this website , thanks for contribution.
this seems not working
This script is no longer working. Do you have an update? That would be cool.
After a recent google toolbar update, it is needed to use a different url to get this code to work:
use http://toolbarqueries.google.com/tbr?...
instead of http://toolbarqueries.google.com/search?...
I have learn some just right stuff here. Certainly price bookmarking for revisiting. I surprise how so much effort you put to make such a wonderful informative web site.
please check the update part
google have updated the search url please check the update part
yes it did i have update the content thanks
What a wonderful description! I have no clue how you were able to say this post..it’d take me weeks. Well worth it though, I’d suspect. Have you considered selling banners on your blog?
Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\backlink\pagerank.php on line 88
you have not curl enabled in your server