To get backlinks and indexed page count from Google most webmasters use scrapping Google search page. It is not a good idea because it fails some time and very slow.
So we can use Google Ajax search API instead of scrapping whole page. It will return data in JSON object which is much smaller then html page.
Although Ajax search API is rate limited to 100 queries per IP per Day but still it’s a good way.
PHP code to get Google backlinks count
<? function GoogleBL($domain){ $url="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=link:".$domain."&filter=0"; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $json = curl_exec($ch); curl_close($ch); $data=json_decode($json,true); if($data['responseStatus']==200) return $data['responseData']['cursor']['resultCount']; else return false; } ?>
PHP code to get Google Indexed Page count
<? function GoogleIP($domain){ $url="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:".$domain."&filter=0"; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $json = curl_exec($ch); curl_close($ch); $data=json_decode($json,true); if($data['responseStatus']==200) return $data['responseData']['cursor']['resultCount']; else return false; } ?>
How to use?
Both function take domain name as parameter and will return backlink or indexed page count on success or Boolean false on error.
<? $domain="toolspot.org"; //your domain name echo GoogleBL($domain); //get backlinks echo GoogleIP($domain); //get indexed page ?>
BackLinks are not working, might be version needs to be changed
I have tried to do the same thing as what you did but it doesn’t work
Thanks Dear,
your script is the first correct script…
Thanks…
does it also show dofollow and nofollow ???
to get Google backlinks count need replace url
$url="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=link:%20".$domain."&filter=0";
thankyou sir… this script helped me a lot
nice method, I will try to my site… thanks anyway
Working for me
thank
How to apply this in my blog?
Hello,
How do i use these scripts?
In which file do i put it?
Hi,
This is my code. and it is giving me “No result”. Can you please help me whats wrong here –
$domain = ‘ayunutrients.com’ ; // Url of your desired site to check backlinks.
$url=”http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=link:”.$domain.”&filter=0″;
$ch=curl_init(); // cURL started here
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER[‘HTTP_USER_AGENT’]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$kv_json = curl_exec($ch);
curl_close($ch);
$results=json_decode($kv_json,true);
if($results[‘responseStatus’]==200) {
echo $results[‘responseData’][‘cursor’][‘resultCount’];
} else {
echo ‘ Sorry No reults ! ‘ ;
}
Kindly anyone can tell me that it just returns true or false i need to return value of counted google indexed pages in integer value how i could do that?
Do I need additional IP’s or proxy to run this script sir?
thanks 🙂
This request now (07-12-2016) return this :
“The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)” !! so plz update !!
Hi, @Atef
I have same problems.
Do you have any solutions?
Hi! Can this be done using Google Apps Script instead of PHP so the data can be added to a Google spreadsheet? Or no?
Thanks!
Thanks but not working