wordpre

wordpre 

<pre name="code" class="php">function.php文件的最后加上这段

 


/** * 验证码测试 * */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 "<p>"; echo "<label>". $register_questions[$register_number]."<br />"; echo "<input type='text' name='user_proof' id='user_proof' class='input' size='25' tabindex='20' />"; echo "</label>"; echo "</p>";}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', '<strong>错误</strong>: 您还没有回答问题。' ); } elseif ( strtolower( $_POST[ 'user_proof' ] ) != $register_answers[$register_number] ) { return $errors->add( 'prooffail', '<strong>错误</strong>: 您的回答不正确。' ); }}

 


 

wordpre

上一篇:win10右键将文件或图片等另存为时,文件资源管理器总是卡死, 需要一两分钟后才能正常使用


下一篇:L1正则与L2正则