防止垃圾注册,在UCHOME注册页加入reCaptcha!
前两天我在论坛里写了一篇有关如何在uchome批量删除垃圾日志,和如何在uchome批量删除垃圾用户的帖子。我提到删除垃圾注册不是也制止垃圾用户的最终办法。今天我就要和大家分享一招可以理论制止垃圾注册的方法 – 使用reCaptcha!
UCHOME的图片验证码防灌水功能很弱,根本挡不住那些注册机。这个我相信很多使用UChome的站长都深有同感吧?这就是为什么我要用到reCaptcha。2009年reCapcha被Google收购(2009年9月16日Google收购了reCaptcha)。reCaptcha用到的图片是来自一些破损难辨的典籍,使用者在识别它的过程中也给这些典籍的数字化做贡献。本文要介绍的是如何在UCHome注册页里加入reCaptcha。
注册reCaptcha
你需要先注册一个帐号,因为Google收购了reCaptcha,所以你可以使用Google的邮箱登入
。之后你要输入你的域名,就可以得到一个public key和private key, 这两个密钥将要用在下面的代码里。
下载reCaptcha PHP库
点这里
下载。下载后把recaptchalib.php文件上传到UCHOME根目录下的source文件夹里。
修改do_register.php
这个文件在UCHOME根目录下的source文件夹里,打开这个文件,加入下面的代码。注意:修改部分用“####BY hellonet8.com”标识
<?php
/*
[UCenter Home] (C) 2007-2008 Comsenz Inc.
$Id: do_register.php 13111 2009-08-12 02:39:58Z liguode $
*/
####BY hellonet8.com - 这里加入三行
require_once('recaptchalib.php');
$publickey = "xxx"; //替换为第一步里获取的public key
$privatekey = "yyy"; //替换为第一步里获取的private key
......
......
if(!$_POST['password'] || $_POST['password'] != addslashes($_POST['password'])) {
showmessage('profile_passwd_illegal');
}
####BY hellonet8.com - 在这里加入下面几行
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
showmessage('incorrect_code');
}
修改do_register.html
此文件位于UCHome根目录下template/default/文件夹里。打开这个文件做如下更改。注意:修改部分用“####BY hellonet8.com”标识
<script type="text/javascript">// <![CDATA[
function register(id, result) {
if(result) {
$('registersubmit').disabled = true;
window.location.href = "$jumpurl";
} else {
#### BY hellonet8.com, 加入下面这句,目的是在提交出现错误时,重刷验证代码
Recaptcha.reload();
updateseccode();
}
}
// ]]></script>
......
......
<!--{else}-->
<tr>
<th style="vertical-align: top;">验证码</th>
<td>
<script>seccode();</script>
<p>请输入上面的4位字母或数字,看不清可<a href="javascript:updateseccode()">更换一张</a></p>
<input type="text" id="seccode" name="seccode" value="" onBlur="checkSeccode()" tabindex="1" autocomplete="off" /> <span id="checkseccode"> </span>
</td>
</tr>
<!--{/if}-->
<!--{/if}-->
####By hellonet8.com - 这里加入以下代码
<tr>
<th style=style="vertical-align: top;">超强验证码</td>
<td>
<!--{eval echo recaptcha_get_html($publickey);}-->
</td>
</tr>
取消UCHOME自带验证
登入高级管理 -> 防灌水设置 -> 取消注册页面开启验证码功能,最后更新一下系统的缓存。
貌似有点麻烦,但是请相信我,这绝对是一劳永逸!







这篇文章目前没有评论