WordPress 怎样通过php禁止ip访问

Published
2023-03-24
浏览次数 :  319

function block_visitors_by_ip() {
    $blocked_ips = array('xxx.xxx.xxx.xxx'); // Replace with the IP address you want to block.
    if (in_array($_SERVER['REMOTE_ADDR'], $blocked_ips)) {
        header("HTTP/1.1 403 Forbidden");
        exit();
    }
}
add_action('init', 'block_visitors_by_ip');

  • 标签1
  • 标签1
  • 标签1
Top