之前用Discuz弄了一个物理学论坛,但是郁闷的是冒出来注册机,然后一大堆的垃圾注册。又不发贴啊什么的,然后到现在为止,只有一个邮箱验证的~然后就立马把那些注册的id给删了~~可是,又冒出来了~~ :cry:

于是就找防注册,但是事实上DZ自带的那些是没效果的~~后来就想到某个很有名的验证码,找了下,就是reCAPTCHA。

http://www.ylsnuha.com/wp-content/uploads/auto_save_image/2011/11/133724sxw.jpg

首先在http://www.google.com/recaptcha申请账号,注册你的网站,获取Public Key和Private Key

下载recaptcha-php-1.11

在/source/include文件夹下新建一个recaptcha文件夹,将下载的recaptchalib.php文件复制到该文件夹内。

打开/source/class/class_member.php

查找409行:


1
 $username = dhtmlspecialchars($username);

在上面添加:


1
2
3
4
5
// recaptcha hack start
 require_once DISCUZ_ROOT.'./source/include/recaptcha/recaptchalib.php';
 $recaptcha_publickey = '这里替换为你申请到的Public Key';
 $recaptcha_show = recaptcha_get_html($recaptcha_publickey);
 // recaptcha hack end

查找460行:


1
$username = addslashes(trim(dstripslashes($username)));

在上面添加:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// recaptcha hack start
 require_once DISCUZ_ROOT.'./source/include/recaptcha/recaptchalib.php';
 $recaptcha_privatekey = '这里替换为你申请到Private Key';
 $resp = recaptcha_check_answer ($recaptcha_privatekey,
 $_SERVER["REMOTE_ADDR"],
 $_POST["recaptcha_challenge_field"],
 $_POST["recaptcha_response_field"]);
 if (!$resp->is_valid) {
 // What happens when the CAPTCHA was entered incorrectly
 if ($resp->error = 'incorrect-captcha-sol') {
 $resp->error = "验证码输入不正确,请按"刷新"按钮重新获取验证码并再试一次。";
 }
 showmessage('reCAPTCHA failed. reCAPTCHA said: ' . trim($resp->error));
 }
 // recaptcha hack end

打开template/default/member/register.htm

查找186行:


1
<div id="layer_reginfo_b">

在上面添加:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    <!--{if $recaptcha_show}-->
    <label>
    <script type="text/javascript">
    var RecaptchaOptions = {
    theme: 'custom',
    lang: 'en',
    callback: 'Recaptcha.focus_response_field',
    custom_theme_widget: 'recaptcha_widget',
    custom_translations: {
    play_again: "重播",
    cant_hear_this: "下载MP3"} };
    </script>
    <div id="recaptcha_widget" style="display:none">
    <div id="recaptcha_image"></div>
    <div class="recaptcha_only_if_incorrect_sol" style="color:red">输入验证码错误,请重试一次。</div>
    <span class="recaptcha_only_if_image">验证码:</span>
    <span class="recaptcha_only_if_audio">输入您听到数字:</span>  
    <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" /> *
    <span><a href="javascript:Recaptcha.reload()">刷新</a></span>
    <span class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">声音</a></span>
    <span class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">文字</a></span>
    <span><a href="javascript:Recaptcha.showhelp()">?</a></span>
    <p>$recaptcha_show</p>
    </label>
    <p style="color: blue;">提示: 为提高输入验证码成功率,当您感到验证码辨识困难时,</p>
    <p style="color: blue;">请按上面的刷新按钮重新获取新的验证码,直到您满意为止。</p>
    <!--{/if}-->

进入管理后台,全局——防灌水设置——验证码设置,取消新用户注册验证;
界面——界面设置——启用浮动窗口——取消注册窗口浮动
更新缓存,OK。