Jump to content

Archived

This topic is now archived and is closed to further replies.

Seamless

Auto backlink checker

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
ahh, nice one. Cheers Liam.

i thought 'foreach' was doing the loop!

anyway its working, but i think its only checking the first page of the site is that correct??

Seamless

Share this post


Link to post
Share on other sites
Yes it is only checking the first page of the site.. i'm not personaly sure how you would get all the pages without logging them yourself in the database..

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
yes that's correct mate.. im not sure exacly how you would spider it but if you do you could make a nice little search engine :)

Share this post


Link to post
Share on other sites

×

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.