支付宝赞助帐号:service@kuitao8.com 

php禁用ip访问的简单实现方法

Created2015-07-06   Views 1704    Author 懒人程序
$sql = "192.168.0.168
127.0.0.1";
function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }
 
 
    return $realip;
}
$ip = getIP();
$array = explode("\n",$sql);
if(in_array($ip,$array)){
    exit('无权防问');
} else {
    echo $ip;
}
上一篇: thinkphp3.2 文件上传
下一篇: yii2.0 利用Activedataprovider分页
支持键盘 ← →

邮件订阅

订阅我们的精彩内容