/*
This is the part I need, but is corrupting everything else...
$backlinkSources = array();
$result = mysql_query("SELECT website FROM `free_listings`");
while($row = mysql_fetch_assoc($result))
{
$backlinkSources[] = $row;
}
print_r($backlinkSources);*/
$backlinkSources = array ('http://www.safehandsplans.co.uk','http://www.google.com');
$reportArray = array();
$falseFound = false;
foreach ($backlinkSources as $source) {
$html = file_get_contents ( $source );
$links = ExtractHrefLinks($html);
if (CheckForTargetUrl($links, $url) === false) {
$falseFound = true;
$reportArray[$source] = 0;
} else {
$reportArray[$source] = 1;
}
}
print_r($reportArray);
if ($falseFound === true) {
GenerateReportEmail($email, $fromEmail, $subject, $body, $url, $reportArray);
}
function GenerateReportEmail($email, $fromEmail, $subject, $body, $url, $reportArray) {
$header = "From: " . $fromEmail . "\r\n";
foreach ($reportArray as $key => $report) {
if ($report == false) {
$body .= "Backlink to $url not found on: $key\n";
//update as link 0
$sqlUpdate = "UPDATE free_listings SET backlinkactive='0' WHERE website='$key'";
mysql_query($sqlUpdate) or die (mysql_error());
}
}
mail($email, $subject, $body, $header);
}
function CheckForTargetUrl($links, $target) {
foreach ($links as $link) {
if (strpos($link, $target) !== false) {
return true;
}
}
return false;
}
function ExtractHrefLinks($html) {
$dom = new DOMDocument;
$linkUrls = array();
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
$linkUrls[] = $link->getAttribute('href');
}
return $linkUrls;
}