WordPress登陆后台添加验证码
建站教程 阅读WordPress登陆后台添加验证码,最近有个傻鸟一直攻击和尝试我后台登陆密码,所以没办法只能把后台验证码升级了一下,自己采用了随机英语加数字混合验证码,也可以使用wp-math-captcha插件实现验证码功能,还是那一句插件用多了影响网站加载速度影响网速,只需要添加一串代码就行了,不用安装任何插件就能现实验证码功能,今天分享5种登录后台验证码功能,总有一款你喜欢的验证码。
把以下全部代码丢进模板函数 (functions.php)!
/*-----------------------------------------------------------------------------------*/ /* WordPress登陆后台随机混合数验证码 /*-----------------------------------------------------------------------------------*/ # 登录后台添加验证码第一种 function loper_login_english_figures() { # 获取英语和数字随机数, 范围0~99,目前是0~5,5位数 $num1=substr(md5(mt_rand(0,99)),0,5); echo "<p> <label for='math' class='small'>验证码:$num1 </label> <input id='math' type='text' name='sum' class='input' value='' size='25'> <input type='hidden' name='num1' value='$num1'></p>"; } add_action('login_form','loper_login_english_figures'); # 判断验证码是否空白和错误 function loper_login_calculation() { $sum=$_POST['sum']; switch($sum){ case $_POST['num1']:break; case null:wp_die( __( '错误:请填入验证码!' ), '', array( 'back_link'=>true ) );break; default:wp_die( __( '错误:验证码不正确!' ), '', array( 'back_link'=>true ) );} } add_action('login_form_login','loper_login_calculation');
把以下全部代码丢进模板函数 (functions.php)!
/*-----------------------------------------------------------------------------------*/ /* WordPress登陆后台随机数字验证码 /*-----------------------------------------------------------------------------------*/ # 登录后台添加验证码第二种 function loper_login_english_figures() { # 获取两个随机数, 范围0~99 $num1=rand(0,99); $num2=rand(0,99); echo "<p> <label for='math' class='small'>验证码</label> <input id='math' type='text' name='sum' class='input' size='25' placeholder='$num1 + $num2 = ? '> <input type='hidden' name='num1' value='$num1'> <input type='hidden' name='num2' value='$num2'></p>"; } add_action('login_form','loper_login_english_figures'); # 判断验证码是否空白和错误 function loper_login_calculation() { $sum=$_POST['sum']; switch($sum){ case $_POST['num1']+$_POST['num2']:break; case null:wp_die( __( '错误:请填入验证码!' ), '', array( 'back_link'=>true ) );break; default:wp_die( __( '错误:验证码不正确!' ), '', array( 'back_link'=>true ) );} } add_action('login_form_login','loper_login_calculation');
把以下全部代码丢进模板函数 (functions.php)!
/*-----------------------------------------------------------------------------------*/ /* WordPress登陆后台随机数字验证码 /*-----------------------------------------------------------------------------------*/ # 登录后台添加验证码第三种 function loper_login_english_figures() { # 获取两个随机数, 范围0~99 $num1=rand(0,99); $num2=rand(0,99); echo "<p> <label for='math' class='small'>验证码:$num1 + $num2 = ? </label> <input id='math' type='text' name='sum' class='input' size='25'> <input type='hidden' name='num1' value='$num1'> <input type='hidden' name='num2' value='$num2'></p>"; } add_action('login_form','loper_login_english_figures'); # 判断验证码是否空白和错误 function loper_login_calculation() { $sum=$_POST['sum']; switch($sum){ case $_POST['num1']+$_POST['num2']:break; case null:wp_die( __( '错误:请填入验证码!' ), '', array( 'back_link'=>true ) );break; default:wp_die( __( '错误:验证码不正确!' ), '', array( 'back_link'=>true ) );} } add_action('login_form_login','loper_login_calculation');
把以下全部代码丢进模板函数 (functions.php)!
/*-----------------------------------------------------------------------------------*/ /* WordPress登陆后台随机混合数验证码 /*-----------------------------------------------------------------------------------*/ # 登录后台添加验证码第四种 function loper_login_english_figures() { # 获取英语和数字随机数, 范围0~99,目前是0,5【5位数】 $num1=substr(md5(mt_rand(0,99999)),0,5); echo "<p> <label for='math' class='small'>验证码:$num1 </label> <input id='math' type='text' name='sum' class='input' size='25'> <input type='hidden' name='num1' value='$num1'></p>"; } add_action('login_form','loper_login_english_figures'); # 判断验证码是否空白和错误 function loper_login_calculation($redirect, $bool, $errors) { $sum=$_POST['sum']; switch($sum){ case $_POST['num1']:break; case null:$errors->add( 'zlinet', "<strong>错误</strong>:请输入验证码!" ); break; default:$errors->add( 'zlinet', "<strong>错误</strong>:验证码不正确!" );} } add_action('login_redirect','loper_login_calculation', 9, 9);
把以下全部代码丢进模板函数 (functions.php)!
/*-----------------------------------------------------------------------------------*/ /* WordPress登陆后台随机数字验证码 /*-----------------------------------------------------------------------------------*/ # 登录后台添加验证码第五种 function loper_login_english_figures() { # 获取两个随机数, 范围0~99 $num1=rand(0,99); $num2=rand(0,99); echo "<p> <label for='math' class='small'>验证码</label> <input id='math' type='text' name='sum' class='input' size='25' placeholder='$num1 + $num2 = ? '> <input type='hidden' name='num1' value='$num1'> <input type='hidden' name='num2' value='$num2'></p>"; } add_action('login_form','loper_login_english_figures'); # 判断验证码是否空白和错误 function loper_login_calculation($redirect, $bool, $errors) { $sum=$_POST['sum']; switch($sum){ case $_POST['num1']+$_POST['num2']:break; case null:$errors->add( 'zlinet', "<strong>错误</strong>:请输入验证码!" ); break; default:$errors->add( 'zlinet', "<strong>错误</strong>:验证码不正确!" );} } add_action('login_redirect','loper_login_calculation', 9, 9);
本文链接:https://niujc.com/com/1370889.html
晚上好!当前时间为
目前距离2023年春节还有
TOP