php中使用Akismet防止垃圾评论的代码

yipeiwu_com5年前PHP代码库
然而,人无完人,插(件)无完插!Akismet也并非完美,最近, 我常在被Akismet评判为垃圾的留言中找到“好人”的留言,然而,有时时间长了就自动删除了,损失珍贵的友情和留言。
别忘了修改代码中的 __YOUR_AKISMET_KEY__, __YOUR_WEBSITE_URL__ and __YOUR_NAME__
http://www.script-tutorials.com/akismet-spam-protection/
index.php
复制代码 代码如下:

<?
require_once ('classes/Akismet.class.php');
class MySpamProtection {
// variables
var $sMyAkismetKey;
var $sWebsiteUrl;
var $sAuthName;
var $sAuthEml;
var $sAuthUrl;
var $oAkismet;
// constructor
public function MySpamProtection() {
// set necessary values for variables
$this->sMyAkismetKey = '__YOUR_AKISMET_KEY__';
$this->sWebsiteUrl = '__YOUR_WEBSITE_URL__';
$this->sAuthName = '__YOUR_NAME__';
$this->sAuthEml = '';
$this->sAuthUrl = '';
// Akismet initialization
$this->oAkismet = new Akismet($this->sWebsiteUrl ,$this->sMyAkismetKey);
$this->oAkismet->setCommentAuthor($this->sAuthName);
$this->oAkismet->setCommentAuthorEmail($this->sAuthEml);
$this->oAkismet->setCommentAuthorURL($this->sAuthUrl);
}
public function isSpam($s) {
if (! $this->oAkismet) return false;
$this->oAkismet->setCommentContent($s);
return $this->oAkismet->isCommentSpam();
}
}
echo <<<EOF
<style type="text/css">
form div {
margin:10px;
}
form label {
width:90px;
float:left;
display:block;
}
</style>
<form action="" method="post">
<div><label for="author">Author</label><input id="author" name="author" type="text" value="" /></div>
<div><label for="comment">Comment</label><textarea id="comment" name="comment" cols="20" rows="4"></textarea></div>
<div><input name="submit" type="submit" value="Send" /></div>
</form>
EOF;
if ($_POST) {
// draw debug information
echo '<pre>';
print_r($_POST);
echo '</pre>';
// obtain sent info
$sPostAuthor = $_POST['author'];
$sCommentComment = $_POST['comment'];
// check for spam
$oMySpamProtection = new MySpamProtection();
$sAuthorCheck = ($oMySpamProtection->isSpam($sPostAuthor)) ? ' "Author" marked as Spam' : '"Author" not marked as Spam';
$sCommentCheck = ($oMySpamProtection->isSpam($sCommentComment)) ? ' "Comment" marked as Spam' : '"Comment" not marked as Spam';
echo $sAuthorCheck . '<br />' . $sCommentCheck;
}
?>


source.zip

相关文章

PHP fgetcsv 定义和用法(附windows与linux下兼容问题)

PHP fgetcsv 定义和用法   PHP fgetcsv() 函数从文件指针中读入一行并解析 CSV 字段。   与PHP fgets() 类似,不同的是 PHP fgetcsv(...

PHP使用file_get_contents发送http请求功能简单示例

本文实例讲述了PHP使用file_get_contents发送http请求功能。分享给大家供大家参考,具体如下: 服务器端模拟 POST/GET 等请求,使用 CURL 很容易办到(例如...

php使用socket调用http和smtp协议实例小结

本文实例讲述了php使用socket调用http和smtp协议。分享给大家供大家参考,具体如下: socket发送HTTP请求 http协议请求报文格式 get ## 请求方法 请求...

PHP利用APC模块实现大文件上传进度条的方法

php 大文件带进度的上传,一直是一个令php程序员很苦恼的问题。查询baidu 、Google ,大体做带进度的上传方式为:flash+php,socket,apc+php等,下面我介...

PHP 远程文件管理,可以给表格排序,遍历目录,时间排序

PHP 远程文件管理,可以给表格排序,遍历目录,时间排序

复制代码 代码如下: <?php $rootdir="./"; $spacenum=0; $filenum=0; $allfilesize=0; echo "<h1>文...