2010-10-05 35 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! */