How to Check Google Backlinks of Website using php Code? |
X

Congrats, You are Subscribed to Receive Updates.

How to Check Google Backlinks of Website using php Code?


Note:  The article is old one.  So,it may be deprecated. I will check and rewrite it soon.

There are lot of functions available to check links pointing to a site.  Here is a simple PHP code to list all the links which pointing to your site and remember this  method is one of the traditional way to detect your site backlinks.

<?php
$domain = "kvcodes.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 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'; 
} 
?>

After google panda update, Its not resulting proper results. Because it may leave certain fields. So we have alternative solution to find-out the backlinks.

backlinkchecker

backlinkchecker

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 = 'kvcodes.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 = 'kvcodes.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.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

6 comments

  1. commenter

    Great resources. Thank you.

  2. commenter

    Your blog is very useful. Great article really awesome work.i have collect more information. its really wonderful blog.

  3. commenter

    This code is not working, can you please update the code. It returns the following result.

    {“responseData”: null, “responseDetails”: “The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)”, “responseStatus”: 403}

  4. commenter

    How can I use this sir. I want Google Indexed Page Checker Php script. Can you able to send my mail pls kankalal007@gmail.com.

Reply to Varadharaj V Cancel reply

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

*

Current ye@r *

Menu

Sidebar