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

高洛峰
发布: 2016-11-30 10:20:14
原创
1254人浏览过

然而,人无完人,插(件)无完插!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; 

?> 

代码小浣熊
代码小浣熊

代码小浣熊是基于商汤大语言模型的软件智能研发助手,覆盖软件需求分析、架构设计、代码编写、软件测试等环节

代码小浣熊 51
查看详情 代码小浣熊
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号