關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • PHP + Akismet 過濾 Comment Spam

    Posted on September 29th, 2006 Sam Tang 1 comment

    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:
    1. <?php
    2. include ('Akismet.class.php');
    3.  
    4. // 建立物件,並送出 URL 及 API key
    5. $akismet = new Akismet('http://www.real-blog.com', '[YOUR API KEY]');
    6.  
    7. // $author 是作者名稱
    8. $akismet->setCommentAuthor($author);
    9. // $author_email 是作者電郵
    10. $akismet->setCommentAuthorEmail($author_email);
    11. // $author_url 是作者網站
    12. $akismet->setCommentAuthorURL($author_url);
    13. // $comment 是回應內容
    14. $akismet->setCommentContent($comment);
    15. $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
    16.  
    17. if($akismet->isCommentSpam()) {
    18.     echo "這是 Spam";
    19. } else {
    20.     echo "這不是 Spam";
    21. }
    22. ?>


     

    One response to “PHP + Akismet 過濾 Comment Spam”

    1. [...] PHP + Akismet 過濾 Comment Spam – Real-Blog (tags: Tech WebDev PHP Akismet) [...]

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word