Seamless Posted April 4, 2006 Share Posted April 4, 2006 HiI'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 advanceSeamless Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/ Share on other sites More sharing options...
shocker-z Posted April 4, 2006 Share Posted April 4, 2006 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]RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23798 Share on other sites More sharing options...
Seamless Posted April 4, 2006 Author Share Posted April 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23807 Share on other sites More sharing options...
shocker-z Posted April 4, 2006 Share Posted April 4, 2006 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.. Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23814 Share on other sites More sharing options...
Seamless Posted April 4, 2006 Author Share Posted April 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23816 Share on other sites More sharing options...
shocker-z Posted April 4, 2006 Share Posted April 4, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23825 Share on other sites More sharing options...
Seamless Posted April 4, 2006 Author Share Posted April 4, 2006 hmmm, maybe i'll look into that :PCheers Liam... Quote Link to comment https://forums.phpfreaks.com/topic/6560-auto-backlink-checker/#findComment-23828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.