Google Pagerank in PHP

Due to recent changes made by Google in its Page Rank processing the following library doesn’t work. However you can try to use the following api made available by fusionswift.com:
http://www.fusionswift.com/2011/10/google-pagerank-api-in-php-october-2011/

Mark Woodman has created a nifty class which lets you query Google pagerank info in PHP 5 and above. The complete classes are available here.

The minimum classes required are ‘cacher.class.php‘ and ‘google_pagerank.class.php‘.

Sample code is shown below.

require_once("popstats/google_pagerank.class.php");
 
$rankObject = new GooglePageRank("http://www.someDomain.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):

$rankObject = new GooglePageRank("http://www.someDomain.com", 21600);

The default is set to 24 hours, which is more then adequate for most purposes.

28 thoughts on “Google Pagerank in PHP

  1. This topic is a little old, but files are still there so I’d like to suggest something:
    In line 50 of google_pagerank.class.php file you used ‘urlencode’ function. It works until there is ‘&’ in link string, otherwise ‘&’ is treated as another Google’s parameter. Changing ‘urlencode’ to ‘rawurlencode’ solves the problem.
    Nice work btw!
    P.S. Another little suggestion: try adding cURL (if unable to file_get_contents) and various Google Server (and get it random when checking – that way you won’t have to do ‘usleep’ being afraid of ban from Google).

  2. Good morning,
    we are announcing you Eman Engine Stats, a useful FREE script to show important informations of a web site ranking, backlinks and indexing.
    It is free. We attach you a presentation below.
    A demo version is downloadable from this link and is also attached :
    http://www.siti-web-bologna.it/eman_engine_stats_demo.zip

    The web site of the script is http://www.siti-web-bologna.it
    The full version is downloadable only from our web site with the request of a recip link.

    You can show it on your web page
    For contact : http://www.siti-web-bologna.it
    Thanks and good work to everybody,
    Emanuel Celano

    Eman Engine Stats is an important php and flash script to check your ranking, backlinks and indexed pages directly from your web site (NO DEPENDENCIES from other web sites), every time you desire or automatically with an include file that run like a cronjob.
    Do you want to check your Google Ranking, Alexa Ranking ? Do you want to know the number of backlinks and the number of indexed pages from Google, Yahoo, Msn, Altavista, Alltheweb and to monitor the total value at a glance ? Do you want to look at the differences between two checking, to monitor on real time your search engine visibility ? Useful for web companion of submission and optimization on search engines. Do you want a tool that fit to your graphical page ? You can do it with the possibility to change the flash file background colour by your own.
    Eman Engine Stats is for you ! And it is free ! There are two versions of the script. The lite version that is free and the full version, free for now.
    To use these tools we only request to provide a link back to our site : http://www.siti-web-bologna.it
    The script show also the Google last visit date on your web site and is protected with a login form included into the flash file. It is easy to use thanks to detailed informations of installation step by step.

  3. Nice script could be used for archiving page rank for your sites on a cron job. say, running it once a day. Then, you can see when google is doing another page rank run.

    Which is handy information for you and if you have any customers, for them also!

Comments are closed.