Jump to content

Auto backlink checker


Seamless

Recommended Posts

Hi

I'm fairly new to php and i am building my first php website.

I am allowing users to post there website URLs on my site providing they put a link to my site on theirs. Rather than having to check if they have I wanted a script to check for me.

I found a simple backlink checker on the web which takes URLs from a text file and checks them for links to 'my domain'. I have modified it slightly so that it should update my database accordingly if a link to my site is found on theirs.

Here's the orginal code..

[code]
<?php

$mydomain = "www.mydomain.com"; // Set this to your domain

$list = file_get_contents("sites.txt");

$urls = explode ("\n", $list);

echo "<B>Checking back links to $mydomain....</B><P><FONT SIZE=-1>";

foreach ($urls as $url) {
if (strlen ($url)) {
echo $url . "<B><FONT COLOR=";
if (strpos (file_get_contents($url), $mydomain) != FALSE) {
echo "GREEN> Found";
} else {
echo "RED> Missing";
}
echo "</FONT></B><BR>";
}
}
echo "</FONT>";

?>
[/code]

And here is what i have modified....

[code]
<?
//include db connection info here

$mydomain = "www.mydomain.com"; // Set this to your domain

$sql = "SELECT website FROM table WHERE website like 'http://%'";
$result = mysql_query($sql) or die ("ERROR: ".mysql_error()." with query: $sql");

$urls = mysql_fetch_array($result);

echo "<B>Checking back links to $mydomain....</B><P><FONT SIZE=-1><br />";

foreach($urls as $url){
    if(strlen($url)){
        echo $url . "<B><FONT COLOR=";
            if(strpos(file_get_contents($url), $mydomain) != FALSE){
                // do nothing
                mysql_query("UPDATE table SET show_website='1' WHERE website='$url'");
            }else{
                mysql_query("UPDATE table SET show_website='0' WHERE website='$url'");
            }
        echo "</FONT></B><BR>";
    }
}
echo "</FONT>";

?>
[/code]

My problem is that it only checks the first domain in the list...

Any ideas?

Thanks in advance

Seamless
Link to comment
Share on other sites

You need to loop through the data mate, like this:
[code]<?
//include db connection info here

$mydomain = "www.mydomain.com"; // Set this to your domain

$sql = "SELECT website FROM table WHERE website like 'http://%'";
$result = mysql_query($sql) or die ("ERROR: ".mysql_error()." with query: $sql");

while($urls = mysql_fetch_array($result)) {

echo "<B>Checking back links to $mydomain....</B><P><FONT SIZE=-1><br />";

foreach($urls as $url){
    if(strlen($url)){
        echo $url . "<B><FONT COLOR=";
            if(strpos(file_get_contents($url), $mydomain) != FALSE){
                // do nothing
                mysql_query("UPDATE table SET show_website='1' WHERE website='$url'");
            }else{
                mysql_query("UPDATE table SET show_website='0' WHERE website='$url'");
            }
        echo "</FONT></B><BR>";
    }
}
echo "</FONT>";
}
?> [/code]

Regards
Liam
Link to comment
Share on other sites

So am i right in thinking that the 'file_get_contents()' function checks the page source?

If i get the users to enter their 'links page' and use that in the check, it should work out ok.

I guess it would have to be somekind of crawler/spider to follow the links on peoples website to eventually find the link to my site.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.