最近越来越多使用wordpress建站的童鞋给网站加上了用户中心功能,并且开放了网站注册,但是随之而来的就是大量的机器注册的垃圾用户,有些童鞋非常机智的利用插件给注册单表加上了验证码,有些童鞋则想给注册单表添加一个验证问答,其实也推荐大家使用验证问答,这样对于某些限制注册的网站非常适用,某些网站可能仅仅只开放给部分人群,则可以仅仅将答案告诉那部分人群即可,这样的效果验证码显然不能实现。先上一张效果图: 将下面的代码添加到主题的 functions.php 即可: [cc lang=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”php\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”] add_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’register_form\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’add_security_question\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); function add_security_question() { ?>

add( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’proofempty\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’错误: 您还没有回答问题。\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); // 如果答案不正确 } elseif ( strtolower( $_POST[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’user_proof\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] ) != v7v3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ) { return $errors->add( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’prooffail\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’错误: 您的回答不正确。\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); } }[/cc] 另外还可以添加多个随机问题,代码如下: [cc lang=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”php\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”] function rand_reg_question(){ $register_number=rand(0,1); // 设置随机数的返回范围 $_SESSION[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’register_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]=$register_number; } add_action(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’login_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’rand_reg_question\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

global $register_questions; global $register_answers; // 添加问题数组 $register_questions=array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’秦始皇是哪个朝代的君主?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’共产党的理论基础是什么?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’); // 添加答案数组(与上面的问题对应) $register_answers=array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’秦代\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’马列主义\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

add_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’register_form\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’add_security_question\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); function add_security_question() { global $register_questions; $register_number=$_SESSION[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’register_number\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’]; ?>

add( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’proofempty\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’错误: 您还没有回答问题。\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); } elseif ( strtolower( $_POST[ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’user_proof\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ] ) != $register_answers[$register_number] ) { return $errors->add( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’prooffail\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’错误: 您的回答不正确。\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); } }[/cc] 注:请编辑 14 和 16 行修改问题和答案,如果你修改了问题的数量,请记得修改第 6 行的 随机数返回范围 rand(0,1) ,比如 3 个问题,修改为 rand(0,2)。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:< a href="https://wpa.qq.com/msgrd?uin=30115776" target="_blank" rel="noopener noreferrer">点击这里给我发消息</ a>

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部