php中使用Akismet防止垃圾评论的代码
2015-01-24信息快讯网
别忘了修改代码中的 __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
asp.net 组合模式的一个例子
PHP学习笔记 IIS7下安装配置php环境
记录PHP错误日志 display_errors与log_errors的区别
仿Aspnetpager的一个PHP分页类代码 附源码下载
PHP中数字检测is_numeric与ctype_digit的区别介绍
如何获知PHP程序占用多少内存(memory_get_usage)
PHP管理内存函数 memory_get_usage()使用介绍
详解php的魔术方法__get()和__set()使用介绍
php中判断文件存在是用file_exists还是is_file的整理
PHP中file_exists与is_file,is_dir的区别介绍
PHP setTime 设置当前时间的代码
PhpMyAdmin出现export.php Missing parameter: what /export_type错误解决方法
PHP5中新增stdClass 内部保留类
php中通过虚代理实现延迟加载的实现代码
IIS7.X配置PHP运行环境小结
PHP curl_setopt()函数实例代码与参数分析
php自动获取字符串编码函数mb_detect_encoding
php Rename 更改文件、文件夹名称
php的list()的一步操作给一组变量进行赋值的使用
用PHP的超级变量$_GET获取HTML表单(Form) 数据
php中处理mysql_fetch_assoc返回来的数组 不用foreach----echo
php HandlerSocket的使用
php中神奇的fastcgi_finish_request
使用GROUP BY的时候如何统计记录条数 COUNT(*) DISTINCT
fleaphp rolesNameField bug解决方法
PHP session有效期session.gc_maxlifetime
SWFUpload与CI不能正确上传识别文件MIME类型解决方法分享
php 5.3.5安装memcache注意事项小结
The specified CGI application misbehaved by not returning a complete set of HTTP headers
php expects parameter 1 to be resource, array given 错误
php生成的html meta和link标记在body标签里 顶部有个空行
PHP 页面编码声明方法详解(header或meta)