2012-10-21 87 views
-2

我想比較用戶的IP到允許的IP。它說,我的IP是不允許的,當回聲97.103.49.59You do not have permission to do that.比較IP地址在PHP不工作

我想他們像這樣比較:

$ip_address = $_SERVER['REMOTE_ADDR']; 
echo "$ip_address"; 
if(ip_adress=="97.103.49.59") { 
header('Location: Blog.php'); 
} else { 
echo "You do not have permission to do that."; 
} 

回答

3
if(ip_adress=="97.103.49.59") { 

應該讀

if($ip_address=="97.103.49.59") { 
2

你忘了在ip_adress前的$。

if($ip_address=="97.103.49.59") 

應該這樣做。

+1

再次,地址拼錯了 – AlexP

+0

謝謝,我也拼錯了地址哈哈。 – Chris

1
if($ip_adress=="97.103.49.59") { 

你忘$有..

+1

地址拼寫錯誤 – AlexP

3

應該

if($ip_address=="97.103.49.59") 

你也可以允許或拒絕特定範圍

$start = ip2long("97.103.49.1"); 
$end = ip2long("97.103.49.255"); 
$ip = ip2long($_SERVER['REMOTE_ADDR']); 

if ($ip >= $start && $ip <= $end) { 
    // In range 
}