PHP Code to Get the Google Pagerank of Any Page
By Christian Little • Aug 29th, 2008 • Category: Web DevelopmentSo how many of you have wondered how to get the Pagerank of a webpage and hadn’t had the skills to figure out the coding?
Well today’s brief post is to give you the solution – below is a link to a simple text file that will give you all the code needed.
Simply download the file, rename it to pagerank.php, and then put the following two lines of code into your PHP scripts:
include(”pagerank.php”); //be sure to include the full path to wherever you put this file
echo get_pagerank(”http://www.christianlittle.com”);
The get_pagerank() function will return an integer with the pagerank of the page you inputted. Most people use this type of script to find the PR of their homepage, but there are other uses (I personally like to see the PR of actual content pages on my sites after a PR update).
IMPORTANT NOTE: The coding uses CURL to gather the data from Google. This script will not work if CURL is not enabled on your hosting account, so be sure to check with your web hosting provider.
PHP Code: Click Here
Good luck!
Christian Little is a web monkey and owner of this website. Aside from blogging about webmastering, SEO, and marketing, he spends his time with his family, running too many websites, playing counter-strike, and provides SEO consulting for a few select clients around the world.
Email this author | All posts by Christian Little


Thanks for the php file…. i really like this code and i am gonna use it.
Thanks alot.
Imrans last blog post..Enviornment friendly Products
Hi.
I was wondering if your script shows page rank NA too or it just shows 0 for those pages.
Hey Rahman,
The script will show Pagerank 0 for a site that doesn’t have it.
Example Here
Interesting post. However, I just stick to the old-fashioned way of getting my site a page rank. Simply building inbound links baby. And that’s the way it should be. Unless you think actual content quality should be a factor.
How to get a google page ranks last blog post..How to get a Google Page Rank
Good script. Can you provide more please. Like last google accessed? Thanks!
web designs last blog post..Traffic Generator
web deisgn – I’m afraid that’s not possible. Google can provide you that information via their Google Webmaster Tools, but it’s a violation of their TOS to share that information. You could hire a programmer to export that somehow, but there’s not really much point.
hi good script.
I just want to get how many Inbound links in PHP. Can you please make this script.
Hi Ved – if you take a look at this tool it does what you want. But to be completely honest, there’s hundreds of free tools out there that do it for you already that are more advanced that the one I’ve created.
Link: http://www.christianlittle.com/webmaster-tools/quicklook-query/
i have needed this code. it’s really useful. thnx
film izles last blog post..Dokunmay?n ?aban?ma
the script will return -1 if not a pagerank arranged.
I am wondering if it calculates the rank itself or just grab it from somewhere else? I had the similar code before and it was instructed to upload it on some hosting. I did but nothing happened. Should I upload this code to my hosting account and where to out those 2 lines?
Leonardo Medinas last blog post..Pousada Natalli – Cabo Frio / RJ – Brasil
Damn, I haven’t cURL enabled from my hosting provider and that is a shame. I am going to switch to another very soon because it is basically a windows host.
dancing for beginnerss last blog post..Salsa Dancing Video
I think it is much better to have our own tool for this and thanks for sharing the code. I think there is nothing easy than that to implement it.
I have a few plugins in my FF which are efficient enough to grab PR and all other SEO information for me but thanks for sharing the code. I’ll be checking it on my own server.
Roger | Tips To Save Moneys last blog post..Privacy
It might be good to determine our page ranks but I think nobody is now caring. I have read some very strict views about PR and it is just a green bar. Of course we need high rankings for high traffic so who cares about that green bar.
What template are you running on this site ? I really like it. Could you post where you got it from ?
Pagerank may be calculated continuously, but there most definitely are parts in the algorithms/spam detection/adsense quality assesment of a site/etc. that use the data which is represented by the toolbar.
Thanks for sharing the code because I missed it in my last windows crashed. I was planning to put it on one of my sites.
do you need to have curl enabled in order to use this script? thanks for sharing
sorry double posting. please delete…
@okazii, It is clearly stated in the post that host must have cURL.
It didn’t work for me. I think that I was doing something wrong with it. I uploaded it on my server and tried to access it but I could find only a blank page.
I have a template and I need some script that would work with contact us page. Your site good at PHP so let me know how can I do that?
Wonderful piece of code man. Thanks.
Kurt Avishs last blog post..Data Recorders of Yemen Airbus Crash Plane Found
hi;
thanks for the code. I have put the code in a loop
echo get_pagerank(”http://www.cccccc.com/”.$target_url[$i]);
but it always returns the sale GR6 .
tks for the advise
jeff
Wonderful! Such a concept is really new to us!
Always return 0 !!
Are there any other similar blogs I can follow up on?
Thanks! I will recommend this to all my friends.
Nice script man. Other websites made it difficult to use their page rank tool.
Hey this is a great script. I modified it a bit for my ease. I had to comment out set_time_limit(0); because my server is in safe mode, but the script still works fine nevertheless.
i tried a few sites and it seems to be working. for christianlittle.com i got pr1 and limos.com i got pr6.
Danke f?r diesen tollen post, sehr infromativ!
Hi,
Thanks for posting this script. I have three others that I use, but Google is getting good at blocking them. Does anyone know how to spoof the toolbar request with a Firefox plug-in?
Well, i just looked at my google toolbar to see what the page rank of my website was, and at first i thought i was penalized. I looked again and noticed it was even gone when i went to google.com. Looks like PR is no longer important.
Well old now, but stlll grabbed the script cant beat free huh
Need a script for PR of all my pages… will mod this one thanks
Steve
Thanks for the script im going to mod it to show PR of all my pages…Cheers
Steve
a free service for everybody and this matter and look good with all good a great site
that great, It so real and helpful, I should share it to my friends.