Jump to content


Photo

Auto backlink checker


  • Please log in to reply
6 replies to this topic

#1 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 04 April 2006 - 10:52 AM

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..

<?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>";

?>

And here is what i have modified....

<?
//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>";

?> 

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

Any ideas?

Thanks in advance

Seamless

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 04 April 2006 - 12:46 PM

You need to loop through the data mate, like this:
<?
//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>";
}
?>

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 04 April 2006 - 01:28 PM

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

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 04 April 2006 - 02:01 PM

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..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 04 April 2006 - 02:16 PM

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.

#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 04 April 2006 - 02:47 PM

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 :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 04 April 2006 - 02:56 PM

hmmm, maybe i'll look into that :P

Cheers Liam...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users