How to get Google PageRank using php

Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to get Google PageRank using php

Post by Neo » Sat Mar 13, 2010 4:56 pm

Step 1: Download following zip file that contain required files from popstats
PageRank.zip
(3.64 KiB) Downloaded 308 times
Step 2: Now you can use call Google PageRank as below.

Code: Select all

require_once("google_pagerank.class.php");
$rankObject = new GooglePageRank("http://www.yourdomain.com/");
$pageRank = $rankObject->pagerank;
echo $pageRank; 
The class also supports result caching on the local machine, so if a second query arrives within the cache time limit the result saved in the local file is returned rather then going out and querying Google.

The ‘GooglePageRank’ class accepts cache time as a second parameter. So if you want to cache the result for 6 hours you set the second parameter for 21600 seconds (6 * 60 * 60):

Code: Select all

$rankObject = new GooglePageRank("http://www.yourdomain.com/", 21600); 
The default is set to 24 hours, which is more then adequate for most purposes.
Post Reply

Return to “PHP & MySQL”