php中使用Akismet防止垃圾评论的代码
2011-06-10 00:00
746 查看
然而,人无完人,插(件)无完插!Akismet也并非完美,最近, 我常在被Akismet评判为垃圾的留言中找到“好人”的留言,然而,有时时间长了就自动删除了,损失珍贵的友情和留言。
别忘了修改代码中的 __YOUR_AKISMET_KEY__, __YOUR_WEBSITE_URL__ and __YOUR_NAME__ http://www.script-tutorials.com/akismet-spam-protection/
index.php
source.zip
别忘了修改代码中的 __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
相关文章推荐
- 使用 Akismet 防止垃圾评论
- 经典代码(一):基于PHP的webservice的使用
- php使用iis服务器怎么配置zend studio的代码调试功能
- PHP安装与使用VLD查看opcode代码【PHP安装第三方扩展的方法】
- php中使用parse_url()对网址进行解析的实现代码(parse_url详解)
- PHP使用token防止表单重复提交的方法
- php 使用pdo防止注入的原理或注意事项
- Cloud9免费云IDE代码编辑平台空间支持Node.js,PHP,Python可使用FTP管理
- 使用APC来保护PHP代码
- PHP使用eval(gzinflate(str_rot13(base64_decode('BASE64加密后内容'))))核心代码的解密
- 使用php代码加亮函数构造php小后门
- 从php网页的代码的编写来防止您的网站被攻击
- PHP下使用CURL方式POST数据至API接口的代码
- 免申请API Key的Akismet 让WordPress减少垃圾评论
- nginx+php使用open_basedir限制站点目录防止跨站
- [PHP插件教程]002.代码包PHP Beautifier的使用
- PHP uniqid()函数可用于生成不重复的唯一标识符,该函数基于微秒级当前时间戳。在高并发或者间隔时长极短(如循环代码)的情况下,会出现大量重复数据。即使使用了第二个参数,也会重复,最好的方案是结
- 【PHP】富文本HTML过滤器:HTMLPurifier使用教程(防止XSS)