阻止機器人亂貼廣告
你的新聞發佈區、提供下載區經常被不知名人士貼了亂七八糟的色情、賭場........之類的廣告嗎?一般情況下,這些就是所謂的「機器人廣告」。這樣的機器人可以在好幾個國家的ip之間轉換、在一分鐘之內環繞地球一圈;「封鎖ip」這個方法根本拿他沒輒。
當然,並非拿他毫無辦法!!
你可以安裝 NukeSentinel 的防衛套件
或者,在適當的地方插入一些限制程序,讓非會員的「機器人」不能進入
另一個比較簡單快速的方法,就是比照註冊程序,自己動手安裝一道「安全辨識碼」的守門員;這個作法只會限制到「機器人」,施工也不難,是比較好的對策
送出一張帶有數字的小圖片,讓提供 news的用戶填寫.........
這樣一來,廣告機器人都過不了門檻了
施工原則:
1.在輸入表單前面,插入一個亂數產生器、識別圖片產生器.......
像這樣:
mt_srand ((double)microtime()*1000000);
$maxran = 1000000;
$checkpass = mt_rand(0, $maxran);
if (extension_loaded("gd")) {
$codepass = "<img src='gfx.php?random_num=$checkpass' border='1' alt='Security Code : $checkpass' width='77' height='20'>";
} else {
$codepass = "<font color=\"#FFFF00\"><b>$checkpass</b></font>";
}
2.接著,在「輸入表單」裡面插入一些零件....... 類似這樣:
<form ...........>
<input type="hidden" name="checkpass" value="$checkpass">
安全確認碼:
<img src='gfx.php?random_num=$checkpass' width='77' height='20'>
在此輸入安全確認碼: <input type="text" size="20" name="passcode">
</form>
上面那個 $checkpass , 就是亂數產生器製造的「亂數」.
3.當表單被送出來之後,我們就在form action 指定的接收端攔截資料,辨識碼正確時放行,辨識碼錯誤就踢回去....
程序如下:
if ($_POST["checkpass"]!=""){
global $sitekey;
$datekey = date("F j");
$rcode = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $_POST['checkpass'] . $datekey));
$code = substr($rcode, 2, 6);
if ($code != $_POST["passcode"]){
header("Location: $url");
exit;
}
}
header("Location: $url"); 也可以換為其他的處置方式,以你的需要為準
識別圖片產生器:gfx.php 可以在本站下載區找到
現在,我們介紹PHP-Nuke-7.9.0.3.2e\modules\Submit_News 「安全辨識碼守門員」的實際製作過程,大家參考一下
施工的範圍就在這裡: PHP-Nuke-7.9.0.3.2e/modules/Submit_News/index.php
首先,在本站下載區找到 gfx.7z,解開之後,把裡面的 gfx.php送入你的網站主目錄底下
第二步:
開啟 PHP-Nuke-7.9.0.3.2e/modules/Submit_News/index.php
在 function PreviewStory 裡面找到這一堆程序:
echo "<input type=\"submit\" name=\"op\" value=\""._PREVIEW."\"> "
."<input type=\"submit\" name=\"op\" value=\""._OK."\"></form>";
把他改成這樣:
mt_srand ((double)microtime()*1000000);
$maxran = 1000000;
$checkpass = mt_rand(0, $maxran);
if (extension_loaded("gd")) {
$codepass = "<img src='gfx.php?random_num=$checkpass' border='1' alt='Security Code : $checkpass' width='77' height='20'>";
} else {
$codepass = "<font color=\"#FFFF00\"><b>$checkpass</b></font>";
}
echo "<br><br>";
echo "<input type=\"hidden\" name=\"checkpass\" value=\"$checkpass\">";
echo "<table><tr><td><b>"._SECURITYCODE.":</b></td><td>$codepass</td></tr>"
."<tr><td><b>"._TYPESECCODE.":</b></td>"
."<td><input type=\"text\" size=\"20\" name=\"passcode\"></td></tr></table><br>";
echo "<input type=\"submit\" name=\"op\" value=\""._PREVIEW."\"> "
."<input type=\"submit\" name=\"op\" value=\""._OK."\"></form>";
接著,找到這些:
function submitStory($name, $address, $subject, $story, $storyext, $topic, $alanguage) {
global $user, $EditedMessage, $cookie, $anonymous, $notify, $notify_email, $notify_subject, $notify_message, $notify_from, $prefix, $db;
if (is_user($user)) {
cookiedecode($user);
$uid = $cookie;
$name = $cookie;
} else {
$uid = 1;
$name = "$anonymous";
}
在下方插入這些:
global $sitekey;
$datekey = date("F j");
$rcode = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $_POST['checkpass'] . $datekey));
$code = substr($rcode, 2, 6);
if ($code != $_POST["passcode"]){
header("Location: index.php"); // 辨識碼不合格者通通踢回首頁
exit;
}
修改之後,畫面看起來是這樣的:
http://upload4.postimage.org/746285/Submit_News.jpg
ok~ 施工完畢,測試看看吧
页:
[1]