Home » » How to Check Google Backlinks of Website using php Code?

How to Check Google Backlinks of Website using php Code?

Written By Unknown on June 25, 2014 | Wednesday, June 25, 2014


There are lots of functions available to ensure links point to a site. Here is a simple PHP code to list all the links which pointing to your site and retain information this method is one of the traditional way to detect your site backlinks.

<?php
$domain = "tutorials-corner.blogspot.com"; //Enter your desired site to check back-links
$url = "http://www.google.com/search?q=link%3A".$domain;
$file = file_get_contents($url);
if (!strstr($file,'did not match any file documents')) {
$linksto = strstr($file,"of about "); 
$linksto = substr($linksto,strlen("of about")); 
$linksto = str_replace(strstr($linksto,''),'',$linksto); 
echo $linksto.' backlinks'; 
}else{ 
echo 'No backlinks'; 
} 
?>

Later than Google panda update, it's not resulting proper results. Because it may leave certain fields. So we have another solution to find-out the backlinks.
We are going to use cURL functions to get the back-link's count and indexed pages list. The following function will help us to get the backlink count.

<?php 
$domain = 'tutorials-corner.blogspot.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 ! ' ; 
} 
?>

The above function will help you to get the total number of backlinks. So if you want to get the indexed pages list, the following code snippet will help you to get the indexed pages list.

>?php
$domain = 'tutorials-corner.blogspot.com' ; // Url of your desired site to check backlinks. $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); 
$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 ! ' ; 
} 
?>
I hope you enjoyed reading my article, if you have any doubts and comments drop below.

4 comments:

  1. copy content fake ...not working

    ReplyDelete
  2. • I very much enjoyed this article. Nice article thanks for given this information. I hope it useful to many Peopledata since Online course

    ReplyDelete
  3. Thank you for sharing such great information very useful to us.
    PHP Training in Gurgaon

    ReplyDelete
  4. Try more codes or SEO tools on seochecker.cc website.
    Thanks for the codes, also

    ReplyDelete