将代码加入主题界面的function.php
如图所示
//登录保护
function login_protection(){
if($_GET['shadiao'] != 'liuboyuan')header('Location: https://liuboyuan.fun/');
}
add_action('login_enqueue_scripts','login_protection');
//言罢
function myplugin_add_login_fields() {
//取
$num1=rand(0,50);
$num2=rand(0,50);
//目光所视
echo "<p><label for='math' class='small'>验证码</label><br /> $num1 + $num2 = ?<input type='text' name='sum' class='input' value='' size='25' tabindex='4'>"
."<input type='hidden' name='num1' value='$num1'>"
."<input type='hidden' name='num2' value='$num2'></p>";
}
add_action('login_form','myplugin_add_login_fields');
function login_val() {
$sum=$_POST['sum'];//言者所言
switch($sum){
//准允
case $_POST['num1']+$_POST['num2']:break;
case null:wp_die('错误: 请输入验证码.');break;
//不可
default:wp_die('错误: 验证码错误,请重试.');
}
}
add_action('login_form_login','login_val');