最近收到小伙伴反应自己的网站总是被莫名其妙的注册,其实在DUX轻语博客加强版之前的版本是有注册验证码的,之后后来取消了,今天就来教给大家如何为自己的网站添加注册验证码
此方法只适用于DUX轻语博客加强版,其他主题可以作为参考,需要帮助可在下方留言!
1、修改loginbox文件,让ajax弹窗有验证码
loginbox.php文件位于主题template文件夹下
将下面代码
<p> <input class="submit inline" type="submit" value="注册" name="submit"> </p>
替换为
<p id="captcha_inline"> <input class="input-control inline" type="text" id="um_captcha" name="um_captcha" placeholder="输入验证码" required> <img src="<?php echo THEME_URI.'/template/captcha.php?'.str_replace(' ', '_', microtime()); ?>" class="captcha_img inline" title="点击刷新验证码"> <input class="submit inline" type="submit" value="注册" name="submit"> </p>
2、增加验证码验证以及后台注册验证码
将以下代码添加到主题的functions.php文件下
/* 后台注册同时添加验证码 /* ----------------------- */ function _add_register_captcha(){ $captcha = THEME_URI.'/template/captcha.php'; ?> <p style="overflow:hidden;"> <label for="um_captcha">验证码<br> <input type="text" name="um_captcha" id="um_captcha" aria-describedby="" class="input" value="" size="20" style="float:left;margin-right:10px;width:175px;"> <img src="<?php echo $captcha; ?>" class="captcha_img inline" title="点击刷新验证码" onclick="this.src='<?php echo $captcha; ?>';" style="float:right;margin-top: 5px;"></label> </p> <?php } add_action('register_form','_add_register_captcha'); function _add_register_captcha_verify($sanitized_user_login,$user_email,$errors){ if(!isset($_POST['um_captcha'])||empty($_POST['um_captcha'])){ return $errors->add( 'empty_captcha', __( '请填写验证码','um' ) ); }else{ $captcha = strtolower(trim($_POST['um_captcha'])); session_start(); $session_captcha = strtolower($_SESSION['um_captcha']); if($captcha!=$session_captcha){ return $errors->add( 'wrong_captcha', __( '验证码错误','um' ) ); } } } add_action('register_post','_add_register_captcha_verify',10,3);
修改template/captcha.php文件第4行代码为
$font = $um_dir."/fonts/consolas-webfont.ttf";
阅读全文
好棒
来看看
正需要
感觉很不错,之前用你的那个弹窗登录界面,设置好了,现在就差这个验证码了,可惜没有这个文件,呵呵