php 如何限制只能公司IP才能進入公司網站
將以下程式碼載入所有有限制的頁面裡面即可
並修改紅色字眼開放的IP位置
---------------------------------------------------------------------------------------
// 是否鎖定IP位置
$cfg['iplock'] = True;
// 開放的IP位置,請以|做區分
$cfg['WanIPList'] = "110.0.0.1|111.0.0.1";//外部IP
$cfg['LanIPList'] = "192.168.0";//內部IP
//取得使用者IP --- Start
function GetIP(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}
//取得使用者IP --- End
//判斷是否有啟用鎖IP判斷
if ($cfg['iplock']){
$User_Ip = GetIP();
$CheckWanIP = explode("|",$cfg['WanIPList']);
$CheckLanIP = explode("|",$cfg['LanIPList']);
$User_Ip_Lan = explode(".",$User_Ip);
$User_Ip_Lan = $User_Ip_Lan[0].".".$User_Ip_Lan[1].".".$User_Ip_Lan[2];
if (!in_array($User_Ip_Lan,$CheckLanIP)){
if (!in_array($User_Ip,$CheckWanIP)){
echo "對不起!!您無法使用本系統,請聯絡系統管理員!!";
exit;
}
}
}
引用 http://tw.knowledge.yahoo.com/question/question?qid=1009092102778
並修改紅色字眼開放的IP位置
---------------------------------------------------------------------------------------
// 是否鎖定IP位置
$cfg['iplock'] = True;
// 開放的IP位置,請以|做區分
$cfg['WanIPList'] = "110.0.0.1|111.0.0.1";//外部IP
$cfg['LanIPList'] = "192.168.0";//內部IP
//取得使用者IP --- Start
function GetIP(){
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}
//取得使用者IP --- End
//判斷是否有啟用鎖IP判斷
if ($cfg['iplock']){
$User_Ip = GetIP();
$CheckWanIP = explode("|",$cfg['WanIPList']);
$CheckLanIP = explode("|",$cfg['LanIPList']);
$User_Ip_Lan = explode(".",$User_Ip);
$User_Ip_Lan = $User_Ip_Lan[0].".".$User_Ip_Lan[1].".".$User_Ip_Lan[2];
if (!in_array($User_Ip_Lan,$CheckLanIP)){
if (!in_array($User_Ip,$CheckWanIP)){
echo "對不起!!您無法使用本系統,請聯絡系統管理員!!";
exit;
}
}
}
引用 http://tw.knowledge.yahoo.com/question/question?qid=1009092102778
留言
張貼留言