return link checking
Posted: Thu Nov 26, 2009 5:40 am
im trying to allow users to add links to my links page themselves. but only display links where i have a rteturn link back to me
ive created the table in database, the form, a page to check form data and then inserts data into database, ive got a page that displays the checked links
but now im trying to do the return link checking, id be grateful if someone could go through and check my code
im only a php beginner so expect silly mistakes
ive tried to be as descriptive as i can to what im doing.
if you do find any mistakes id be very gratful if you could explain why its wrong
thanks in advance
ive created the table in database, the form, a page to check form data and then inserts data into database, ive got a page that displays the checked links
but now im trying to do the return link checking, id be grateful if someone could go through and check my code
im only a php beginner so expect silly mistakes
ive tried to be as descriptive as i can to what im doing.
Code: Select all
<?php
include_once 'Connect.php';
// FIRST I WANT TO GET LINKFROM COLUMN DATA FROM DATABASE - THIS CONTAINS URL's TO PAGES WHERE I WOULD EXPECT A RETURN LINK BACK TO MY SITE
$query = ("SELECT * FROM links");
$result= mysql_query ($query) or die ('Could not query.');
// SO I DEFINE MY URL
$mylink = "http://www.yoururlhere.com";
// I THEN WANT TO CHECK EACH ROW
while ($row = mysql_fetch_assoc($result))
{
$linkto = $row["linkto"];
// FROM THE URL STORED IN DATABASE COLULMN GET THE URL PAGE RETURN AS A STRING
$linkcheckcontents = file_get_contents ($row['linkfrom']);
if ($linkcheckcontents == FALSE) echo 'Could not open';
else
{
//CHECKS THE LINK RETURNED AS A STRING CONTAINS MY $MYLINK
if( (stristr($linkcheckcontents, '<a href="'.$mylink) === FALSE) && (stristr($linkcheckcontents, "<a href='" .$mylink) === FALSE))
{
// IF $MYLINK DOESNT APPEAR SET checked='0'
$query = ("UPDATE links SET checked='0' WHERE linkfrom='$linkfrom'");
$result= mysql_query ($query) or die ('Could not query.');
}
else
{
// IF $MYLINK APPEARS SET checked='1'
$query = ("UPDATE links SET checked='1' WHERE linkfrom='$linkfrom'");
$result= mysql_query ($query) or die ('Could not query.');
}
}
// GOES BACK TO START AND REPEATS FOR NEXT ROW
}
?>thanks in advance