WordPress 內建 Akismet 這個 plugin 過濾 spam,我啟動了這個 plugin 後發覺 spams 都數量減少了很多。而 Akismet 也可以用在自行開發的程式上,個人使用是免費的,商業使用才需付費。
Akismet 提供了完整的 API documentation,但其實已經有很多熱心的 developers,將現成 Libraries 及 plugins 放到 Akismet Development Page,我將會示範使用 PHP 4 class by Bret Kuhns,首先下載 PHP4 Akismet Class,解壓後將 Akismet.class.php 上載到 web server。
以下是 coding 的步份:
CODE:
-
<?php
-
include ('Akismet.class.php');
-
-
// 建立物件,並送出 URL 及 API key
-
$akismet = new Akismet('http://www.real-blog.com', '[YOUR API KEY]');
-
-
// $author 是作者名稱
-
$akismet->setCommentAuthor($author);
-
// $author_email 是作者電郵
-
$akismet->setCommentAuthorEmail($author_email);
-
// $author_url 是作者網站
-
$akismet->setCommentAuthorURL($author_url);
-
// $comment 是回應內容
-
$akismet->setCommentContent($comment);
-
$akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
-
-
if($akismet->isCommentSpam()) {
-
echo "這是 Spam";
-
} else {
-
echo "這不是 Spam";
-
}
-
?>
[…] PHP + Akismet 過濾 Comment Spam - Real-Blog (tags: Tech WebDev PHP Akismet) […]
Pingback by -TMA-1- » links for 2006-10-11 — October 11, 2006 @ 8:24 am