wordpress注册加上问题验证

 

 


/** * 验证码测试 * */function rand_reg_question(){ $register_number=rand(0,1); // 设置随机数的返回范围 ,如果有三个问题,修改为0,2以此类推 if(!isset($_SESSION)){ session_start(); } $_SESSION['register_number']=$register_number;}add_action('login_head','rand_reg_question');global $register_questions;global $register_answers;$register_questions=array('树上4只鸟,开了一枪打死一只还剩多少鸟?(数字)','小明的有3兄弟,大个叫大明。二哥叫二明,三哥叫什么?');// 可以继续添加问题和答案 ,注意格式即可$register_answers=array('0','小明');add_action( 'register_form', 'add_security_question' );function add_security_question() { global $register_questions; $register_number=$_SESSION['register_number']; echo "

"; echo ""; echo "

";}add_action( 'register_post', 'add_security_question_validate', 10, 3 );function add_security_question_validate( $sanitized_user_login, $user_email, $errors) { global $register_answers; $register_number=$_SESSION['register_number']; if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) { return $errors->add( 'proofempty', '错误: 您还没有回答问题。' ); } elseif ( strtolower( $_POST[ 'user_proof' ] ) != $register_answers[$register_number] ) { return $errors->add( 'prooffail', '错误: 您的回答不正确。' ); }}

 

 

wordpress注册加上问题验证_第1张图片

你可能感兴趣的:(wordpress注册加上问题验证)