Validate Backlinks To Your Site

Connections!


Validate a backlink to your website

Most of the time, if you’re in the link exchange business you’ll need a way to check for your backlinks. You can either use a software for that or a script you have implemented or found over the internet.

Today I’ll show you another way of checking a backlink, the simple way I’d say.

Firstly, you’ll need the jQuery library for PHP. Okay, just kidding, there’s no jQuery library for PHP, but there is another great php script that is for PHP exactly what jQuery is for JavaScript, and that is simple_html_dom. If you want to learn more about it you can either check a previously blog post I’ve written about it (with some working real examples), or you can check its online documentation.

I cannot tell you how much I love this script, I love jQuery too, so when I’ve found this script I felt like I was blessed!

So let’s get started, shall we?

The code, as you can see below, it’s pretty straightforward and self explanatory, so I won’t bore you with the details.

//@ Import simple_html_dom script
	require('simple_html_dom.php');
 
/*!
| @Check the backlink to your website
| @param string The path to the website/page where
| the $checkLinkUrl should be found
| @param string The url to check for existance
| @param boolean Whether or not to inspect the link
| for the nofollow attribute. Defaults to true.
| @return boolean
*/
function CheckReciprocal( $targetUrl, $checkLinkUrl, $checkNofollow = true )
{
	$html = file_get_html($targetUrl);
	if (empty($html))
	{
		//@ Could not load file
		return false;
	}
 
	//@ CHECK IF LINK EXISTS
	$link = $html->find('a[href^='.$checkLinkUrl.']',0);
	if (empty($link))
	{
		//@ Link not found
		return false;
	}
 
	//@ CHECK FOR THE NOFOLLOW ATTRIBUTE
	if ( $checkNofollow && $link->hasAttribute('rel') )
	{
		$attr = $link->getAttribute('rel');
		return (preg_match("/\bnofollow\b/is", $attr) ? false : true);
	}
 
	//@ All good
	return true;
}
/*! End CheckReciprocal() !*/

Then, the checking is very simple:

//@ The path to the page where to check for the backlink
$targetUrl = 'http://blog.v7n.com/2011/03/17/make-your-website-work/';
 
//@ The url to search for
$checkLinkUrl = 'http://coderevision.com';
 
//@ Check the page for the link and for the nofollow attribute
if ( CheckReciprocal($test, $checkLinkUrl) )
{
	echo 'Link found';
}
else { echo 'Link not found or marked as nofollow'; }

What do you think? Pretty cool, isn’t it?

About The Author

Costin Trifan

Costin Trifan is a 32 years old web developer from Romania. He currently finds PHP more interesting than any other thing in his life and spends way too much time in front of his PC creating websites and scripts like the IrisMVC framework in the hope they’ll help other people just as much as they help him.

You can easily reach him via his blog, or through social media such as Twitter or in the coding section of the v7n forums (most likely).

  1. Shlomo PeretzShlomo Peretz03-29-2011

    Like the article… but there is a software that check that??

  2. CharlieCharlie03-31-2011

    Well i have a question, if i click on the target url, should this generate the auto backlinks or we have to do it manually? one more, is that condition helpful.

    thanks to share.

  3. Costin,
    This is great stuff. If you have the interest in building wordpress plugins or themes, I may have a job for you?

  4. DreamrageDreamrage04-06-2011

    I think I’m going to have a look at the previous blog post and the real examples. This little piece of code looks really powerful and might just come in handy. Thank you for sharing.

  5. Great info and thanks for sharing. I wonder if anyone can just provide a software (free), that can do all these things.. I mean not all SEOs have knowldege in HTML and web page applications..

  6. koskos04-09-2011

    There are some applications that you can use to check your backlinks, but they do a lot more than just checking the backlinks, so I focused on providing a code only for this that anyone can use. All you need to do here is to specify the target url and the link to be searched for. You can automate this by making a form where you can select the links to check and the target urls and then check those pages when you submit the form. Also, this code can be translated into VB or C# and build an app to do that…but where would be the point? as there already are app that do that.

    thank you for your comments! :)

  7. GaryGary04-18-2011

    Costin,
    Thanks for the article. Perhaps you could give me a little guidance. I have site with a form on it for others to submit link requests. When the form is submitted, it calls a php file that writes the form input to a csv file. I then imort this data into Arelis (my semi-automatic link managing software). The code looks like this:

    After studying your code, I found myself wondering how to actually implement it into my current set up. Can you offer a step-by-step explanation on how to set this up please? I’m not sure if I have to put your code into a separate php file or not. Can I put your code into a javascript function that is triggered by the onsubmit call? As you can probably tell, I’m a little new at this. Any help would be much appreciated!

    Thanks,
    Gary Michalske

  8. GaryGary04-18-2011

    No sure if you can see the code I wrote into my earlier post. It disappeared when I posted it. Without the opening and closing php tags, it looks like this:

    $url = $_POST['url'];
    $title = $_POST['title'];
    $description = $_POST['description'];
    $category = $_POST['category'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $reciprocalurl = $_POST['reciprocalurl'];
    $suggest = $_POST['suggest'];

    $csvData = $url.”,”.’”‘.$title.’”‘.”,”.’”‘.$description.’”‘.”,”.$category.”,”.$name.”,”.$email.”,”.$reciprocalurl.”,”.$suggest.”\n”;

    $file=fopen(“linkrequests.csv”,”a”);
    fwrite($file,$csvData);
    fclose($file);

    • koskos04-19-2011

      Gary, firstly, I want to thank you for your comment, secondly, no matter how much I’d try I can’t help you with your issue here, using the blog’s comment box, thus I suggest you to join the v7n’s forums and post your question there and I’ll try to make that script work for you too :)

      • GaryGary04-19-2011

        Thanks, Costin. I’ll go ahead an do that.

  9. J. HarperJ. Harper09-11-2011

    Good stuff. Though there are desktop software and web applications that can achieve the same thing but they provide a whole lot of unwanted information too. I am working on your scripts so that it can take several websites to check simultaneously.

  10. Akash KumarAkash Kumar10-02-2011

    Nice post, thanks for the code.

Leave a Reply