2010-10-05 36 views
3

我已与其他网站进行了链接交换。 3天后,该网站已删除我的链接。检查链接交换

是否有一个简单的PHP脚本来帮助我控制链接交换并通知我,如果我的链接已被删除?

我需要它尽可能简单,而不是整个广告。系统管理员。

回答

4

做如果你知道网页的网址,您的广告(链接)存在,那么你可以使用Simple HTML DOM Parser得到数组该网页的所有链接,然后使用PHP in_array功能检查你的链接是否存在于该数组中。您可以使用crontab以每日为基础运行此脚本。

// Create DOM from URL 
$html = file_get_html('http://www.example.com/'); 

// Find all links 
$allLinks = array(); 
foreach($html->find('a') as $element) { 
    $allLinks[] = $element->href; 
} 

// Check your link. 
$adLink = "http://www.mylink.com"; 
if (in_array($adLink , $allLinks)) { 
    echo "My link exists."; 
} else { 
    echo "My link is removed."; 
} 
0

从技术上讲,没有办法知道某人的网站是否与您的网站有链接,除非您有从他们的网站发送的流量或您查看他们的网站。

您最好的选择是,要么:

它记录每次链接到你的图像时间的脚本。这是通过混合PHP足够简单的.htaccess

.htaccess: 

RewriteRule path/to/myImage.jpg path/to/myScript.php 

myScript.php: 

/* Record (database, file, or however) that they accessed */ 
header("Content-type: image/jpeg"); 
echo file_get_contents("path/to/myImage.jpg"); 

或脚本看起来他们的网站的分钟/小时/天,每X量和搜索返回的HTML链接到您的图像。这里面临的挑战是使脚本定期运行。这可以用crontab中或类似

myScript.php: 

$html = file_get_contents("http://www.theirsite.com"); 
if(strpos($html, 'path/to/myImage.jpg') !== FALSE) 
    /* Happiness */ 
else 
    /* ALERT! */