2012-10-21 86 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 
}