【问题标题】:Bypass on specific ip绕过特定ip
【发布时间】:2016-10-21 13:58:53
【问题描述】:

我正在使用此代码,我的问题是:如何在特定 IP 上绕过此代码:

// Maintenance
$maintenance = 0;if($maintenance):    // 0 = no maintenance, 1 = maintenance
require_once($_SERVER["DOCUMENT_ROOT"] . "/maintenance.php");
exit();
endif;

谢谢

【问题讨论】:

  • 好吧,通过添加一个条件来测试请求是否明显来自该特定 IP。查看$_SERVER中包含的内容...
  • $_SERVER['SERVER_ADDR'] 就是你要找的东西

标签: php ip maintenance


【解决方案1】:

您可以使用$_SERVER environment variable 的REMOTE_ADDR 来实现此目的。

if ( $_SERVER['REMOTE_ADDR'] != "xxx.xxx.xxx.xxx" && $maintenance )
{
    //Display Maintenance Page
    die(include('maintenance.php'));
}

    //Normal stuff

但是,如果用户在代理后面,或者如果您和 Apache/ngix/etc 服务器之间存在 WAF,则您可能必须改用“HTTP_X_FORWARDED_FOR”变量,即如果代理/WAF 适用那个标题。

【讨论】:

    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多