PHP script to count Google backlinks and Indexed Pages

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
  ?>

Liked It? Get Free updates in your Email

Delivered by feedburner

10 thoughts on “PHP script to count Google backlinks and Indexed Pages

  1. Nitin Gupta
    #

    BackLinks are not working, might be version needs to be changed

    Reply
  2. Alya Soraya
    #

    I have tried to do the same thing as what you did but it doesn’t work

    Reply
  3. majid
    #

    Thanks Dear,
    your script is the first correct script…
    Thanks…

    Reply
  4. Randeep Hooda
    #

    does it also show dofollow and nofollow ???

    Reply
  5. stach
    #

    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";

    Reply
  6. miilli
    #

    thankyou sir… this script helped me a lot

    Reply
    1. pakgaol
      #

      nice method, I will try to my site… thanks anyway

      Reply
  7. ulexu
    #

    Hello,
    How do i use these scripts?
    In which file do i put it?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *