Page 1 of 1

can't get easy reciprocal link checker code to work

Posted: Sat May 22, 2004 1:15 am
by auberouge
http://forums.digitalpoint.com/showthre ... nk+checker

Here's the code--

PHP Code:
<?php

$mydomain = "www.yourdomain.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>";

?>
Reads a file (in the same directory) named sites.txt which is a list of URLs to check (separated by a carriage return).

----


found this simple reciprocal link checker but am having the same problem as Bill...

Warning: file_get_contents(http://www.frugalcarrental.com ): failed to open stream: No such file or directory in C:\Web\test\sitetest.php on line 18
RED> Missing


etc.etc.

I've got fopen set to on too. Checked securities & permissions for the file. Don't know where to go from here. 8O

Thanks!!

Posted: Sat May 22, 2004 5:27 am
by launchcode
Two things - file_get_contents is probably failing because it cannot actually find the sites.txt file (that is what the error you posted means). So give it a FULL path to the file instead. You could try this:

$sites_file = $_SERVER['PATH_TRANSLATED'] . 'sites.txt';

or just set the path:

$sites_file = '/usr/home/www/blah/sites.txt';

Also the second thing - if you need the sites in an array, don't use file_get_contents - it's a waste of time. That function returns the results in a string, so you are then having to explode them into an array. Use the file() function instead which will do the exact same thing, only return the results in an array for you already :)

$urls = file($sites_file);

But having said all of that I still don't believe the script will work for a second, that middle loop is just a mess (whoever wrote it!) - try this version?

Code: Select all

<?php
	$mydomain = "www.yourdomain.com"; // Set this to your domain
	
	$sites_list = $_SERVER['PATH_TRANSLATED'] . 'sites.txt';
	$urls = file($sites_list);

	echo "<b>Checking back links to $mydomain....</b><br>";
	
	foreach ($urls as $url)
	{
		$check_url = trim($url);

		if (strpos($check_url, $mydomain))
		{
			echo "$check_url - <font color=green><b>Found</b></font>";
		}
		else
		{
			echo "$check_url - <font color=red><b>Missing</b></font>";
		}
	}
?>
The above is un-tested, but give it a shot.