如何使用Akismet保护任何网站免受垃圾邮件的侵害

news/2024/5/20 12:31:10/文章来源:https://blog.csdn.net/cuke3186/article/details/107838943
practice of using Akismet
practice of using Akismet

Akismet – spam protection. Today we will continue PHP lessons. And today we will talk about spam protection. I think every one have own website, and every one faced with appearing of unwanted content on the site (spam). What is spam? – this is (usually) any message which not relevant to this page – usually just an advertisement of something (and even with a backward link to another site). Yes, you can put the first line of defense – a captcha, but I think spammers are also ready for this and find ways to avoid the CAPTCHA (or, they even can solve its by self). In today’s tutorial I’ll show you how to create a second line of defense against spam – using web services – for example akismet.

Akismet –垃圾邮件防护。 今天,我们将继续PHP课程。 今天我们将讨论垃圾邮件防护。 我认为每个人都有自己的网站,每个人都面临网站上出现有害内容(垃圾邮件)的情况。 什么是垃圾邮件? –这是(通常)与该页面无关的任何消息–通常只是某物的广告(甚至带有指向另一个站点的反向链接)。 是的,您可以设置第一道防线-验证码,但我认为垃圾邮件发送者也已为此做好了准备,并设法避免使用验证码(或者甚至可以自行解决)。 在今天的教程中,我将向您展示如何使用Web服务(例如akismet)为垃圾邮件创建第二道防线。

Akismet is good automated spam protection web service for your website(s). Firstly – open this website, sign up here and obtain own Akismet API key. After, let’s go to Plugins & libraries page, and then, select PHP 5 class by Alex. We will use this class made by Alex for our website.

Akismet是为您的网站提供的出色的自动垃圾邮件防护Web服务。 首先–打开此网站,在此处注册并获取自己的Akismet API密钥。 之后,进入“ 插件和库”页面 ,然后选择AlexPHP 5类 。 我们将在我们的网站上使用Alex制作的此类。

Ok, here are online demo and downloadable package:

好的,这是在线演示和可下载的软件包:

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Ok, download the example files and lets start coding !

好的,下载示例文件并开始编码!

步骤1. PHP (Step 1. PHP)

index.php (index.php)


<?
require_once ('classes/Akismet.class.php');
class MySpamProtection {// variablesvar $sMyAkismetKey;var $sWebsiteUrl;var $sAuthName;var $sAuthEml;var $sAuthUrl;var $oAkismet;// constructorpublic 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 informationecho '<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;
}
?>

<?
require_once ('classes/Akismet.class.php');
class MySpamProtection {// variablesvar $sMyAkismetKey;var $sWebsiteUrl;var $sAuthName;var $sAuthEml;var $sAuthUrl;var $oAkismet;// constructorpublic 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 informationecho '<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;
}
?>

Firstly – don`t forget to configure that class for you – apply your own __YOUR_AKISMET_KEY__, __YOUR_WEBSITE_URL__ and __YOUR_NAME__. And, you will able to use that service without problems. In this PHP code I prepared special own PHP class (MySpamProtection) which will using to check for spam. And, in second part of code – I drawing simple form, and, drawing response from Akismet plus some debug information to you.

首先-不要忘记为您配置该类-应用您自己的__YOUR_AKISMET_KEY __,__ YOUR_WEBSITE_URL__和__YOUR_NAME__。 并且,您将能够毫无问题地使用该服务。 在此PHP代码中,我准备了特殊PHP类(MySpamProtection),该类将用于检查垃圾邮件。 而且,在代码的第二部分–我绘制了简单的表单,并从Akismet绘制了响应,并向您提供了一些调试信息。

classes / Akismet.class.php (classes/Akismet.class.php)

This library I downloaded at ‘PHP 5 class by Alex’ page. Already available in our package.

我在“ PHP 5 class by Alex”页面上下载了该库。 我们的包装中已提供。

现场演示

结论 (Conclusion)

In result, now we have pretty easy class which you can use in your own projects which will help you to validate all incoming data. So you will protected from spam. Happy coding. Good luck in your projects!

结果,现在我们有了一个非常简单的类,您可以在自己的项目中使用该类,这将帮助您验证所有传入的数据。 因此,您将免受垃圾邮件的侵害。 快乐的编码。 在您的项目中祝您好运!

翻译自: https://www.script-tutorials.com/akismet-spam-protection/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_903457.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

通过phpstudy搭建简单的网站

1.简单一键构建&#xff1a;下载phpstudy&#xff0c;开启Apache2.4.39和MySQL5.7.26 选择软件管理--网站程序&#xff0c;选择自己想搭建的网站类型&#xff0c;点击一键部署&#xff0c;设置账户密码&#xff0c;搭建成功 2.如果中途报错&#xff0c;或者端口组冲突&#x…

linux宝塔新建站点

网上查了各种资料&#xff0c;绕了一大圈。有的说域名解析有问题&#xff0c;有的说端口问题&#xff0c;说的都是什么鬼东西啊。我特此在此记录下我自己找到的方法&#xff08;做个笔记&#xff09;。 首先新建立站点如图&#xff1a; 准备步骤&#xff1a;不管有没有域名你都…

分享一些省心的PPT模板下载网站资源(附5G优质PPT模板)

分享一些省心的PPT模板下载网站资源&#xff08;附5G优质PPT模板&#xff09; 每次需要做PPT时&#xff0c;总是为找省心的模板二发愁&#xff0c;用搜索引擎搜索“免费PPT模板”时&#xff0c;展示出的大量所谓“免费”的网站。心动的点开一个后&#xff0c;最终却是&#xf…

分享一些省心的PPT模板下载网站资源(附5G优质PPT模板)

每次需要做PPT时&#xff0c;总是为找省心的模板二发愁&#xff0c;用搜索引擎搜索“免费PPT模板”时&#xff0c;展示出的大量所谓“免费”的网站。心动的点开一个后&#xff0c;最终却是&#xff1a;开通会员才免费&#xff0c;满满的套路 现在我们急需那些&#xff0c;省去搜…

免费PPT模板网站

1、51PPT模板 网址&#xff1a;51pptmoban.com/ppt/ 界面&#xff1a; 下载过程&#xff1a; &#xff08;1&#xff09;点击想下载的模板 &#xff08;2&#xff09;页面向下拉&#xff0c;找到“下载地址” &#xff08;3&#xff09;点击“本地下载”&#xff0c;即可。 2…

免费简历模板网站

免费简历模板网站 1.个人简历网 https://www.gerenjianli.com/moban/ 2.超级简历 https://www.wondercv.com/jianlimoban/ 3.菜鸟图库 https://www.sucai999.com/search/word/0_242_0.html?vNTYxMjky

win2003升级到2012 64bitR2后网站报500错误

服务器从win2003升级到2012 64bitR2后网站开始报500错误 由于2012和原来的2003有很大的区别&#xff0c;很多地都不是很熟悉&#xff0c;后来通过在网上搜索加上自己琢磨算是解决了。现在把我的解决方式写一下&#xff0c;说不定能对遇到同样错误的产生帮助。 1、查阅出错原因…

网站第一次打开加载缓慢问题

需要先检测是否页面加载内容过大&#xff0c;再次检测是否数据库连接问题。。如果简单的页面第一次打开仍然较慢&#xff0c;需要检测应用程序池。应用程序池闲置超时默认为20分钟&#xff0c;如果20分钟之内无人点击&#xff0c;则应用程序池将终止&#xff0c;以便在下次访问…

DISCUZ报错:您的服务器不支持 CURL,这将会导致应用无法安装。请联系您的服务商或者网站技术人员

问题&#xff1a; 解决办法1&#xff1a; 找到文件四个文件 php_curl.dll, libeay32.dll, ssleay32.dll php5ts.dll 复制到系统的C:\WINDOWS\system32下; 修改php.ini&#xff0c;将curl扩展打开 重启服务&#xff0c;问题还是没解决。 查找原因&#xff0c;原来是php文…

网站微信扫码支付开发文档含代码

微信扫码支付文档 前言&#xff1a;2021年2月左右完成&#xff0c;内容借鉴哔哩哔哩的教学视频&#xff08;忘记up的昵称了&#xff09; 1.官方文档 官网链接&#xff1a;https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_7_0.shtml 官方文档&#xff1a;https…

支付宝沙箱电脑网站支付(最详细VUE前端 / JAVA后台)

支付宝电脑网站支付 准备工作 首先需要在支付宝开放平台登录并点击控制台选择开发工具沙箱 这个时候就可以看到自己的APPID 和自己的沙箱账号 后面使用沙箱工具登录支付测试使用 开发工作 Jar包引入 <dependency><groupId>com.alipay.sdk</groupId><ar…

有兴趣送自己一个免费且高大上的个人网站吗

大家好&#xff0c;我是戴先生 废话不说&#xff0c;直接上效果图 ##效果图 获取完整代码&#xff0c;可公众号内回复&#xff1a;vuepress 链接地址&#xff1a;你好&#xff0c;戴先生 ![在这里插入图片描述](https://img-blog.csdnimg.cn/ffb2e67a2f594e6bb5b9fd7b90298…

电脑网站调用支付宝进行支付-Java后台调用支付宝支付

网站调用支付宝进行支付-Java后台调用支付宝支付 本文讲的是使用沙箱环境(支付宝提供的一种开发专用模式&#xff0c;不要实际支付&#xff0c;可以走通整个流程)。 一、准备工作 1.首先要到 蚂蚁金服开发者中心 注册商家账户&#xff0c;并认证。 2.下载java版的sdk和demo …

五步快捷搭建大数据网站

快捷搭建网站 [TOC](快捷搭建网站) 前言一、云服务器二、XSHELL三、端口设置四、一键安装五、上传index.html 前言 如何在最快的时间内搭建一个网站 一、云服务器 首先默认大家已经购买了云服务器&#xff0c;本人这边是使用阿里云的ECS&#xff0c;1Mbps 带宽&#xff0c;40…

识别网站所用技术及所有者——builtwith与whois模块学习笔记

很早前入手了一本网络爬虫的书籍&#xff0c;叫《用Python写网络爬虫》&#xff0c;作者是 Richard Lawson, 李斌翻译&#xff0c;人民邮电出版社出版的书籍&#xff08;封面如图&#xff09;。 刚才大概翻了下&#xff0c;个人感觉不太适合纯新手&#xff0c;比较适合有一些Py…

网站配置https

cerbot 安装 letsencrypt 为你的网站添加 htpps安装 cerbot 工具申请证书配置 nginx更新证书 为你的网站添加 htpps 为了网站的安全&#xff0c;通常会为网站配置 https 。https 需要申请证书, 可以选择付费&#xff08;阿里云&#xff09;&#xff0c;免费&#xff08;腾讯云…

手把手教你掌握网站建设、APP设计以及Logo和图标生成

一文带你掌握网站建设、APP设计以及Logo和图标生成 网站建设服务器USBwebserver简介USBwebserver使用方法 程序WordPress简介 域名 APP设计APP开发APP原型设计了解MockPlus使用Mockplus进行APP原型设计 LOGO和图标&#xff50;&#xff48;&#xff4f;&#xff54;&#xff4f…

【天赢金创】0 基础怎样开始学习做网站 (Ruby on Rails)?

这是参加Rails Girls之后写的&#xff0c;最开始想发这边&#xff0c;不过感觉这里工程师大概占90%了(剩下10%是HR)&#xff0c;倒没有太多初学者会来看&#xff0c;所以一直没发 实际上&#xff0c;也不是0基础的教程。原标题为Rails in Plain Language&#xff0c;即用浅显的…

如何将写好的网站放到云服务器上

从阿里云购买了云服务器&#xff0c; 选择了java运行环境&#xff08;MYSQL、Tomcat、Nginx、JDK等&#xff09;。点击阿里云右上角的备案&#xff0c;进行备案。备案完成之后&#xff0c;进行域名解析。下载Xshell 6、Xftp 6及使用教程打开Xshell并建立和云服务器的远程连接后…

IntelliJ IDEA 搭建一个比较完整的网站实例 1

首先&#xff0c;电脑上安装IDEA&#xff0c;jdk&#xff0c;mysql&#xff0c;maven以及tomcat&#xff0c;这几样都是单独安装的&#xff0c;安装完成之后需要配置环境变量&#xff0c;网上教程也有很多&#xff0c;这里就不多叙述了。我这里所用到的mysql是8.0版本&#xff…