Home  >  Article  >  php教程  >  根据IP 判断来自地区

根据IP 判断来自地区

WBOY
WBOYOriginal
2016-06-08 17:29:511783browse

下面是一段简单的IP 判断来自地区哦,我们只要根据用户当前IP就可以判断此用户来自哪里哦。

<script>ec(2);</script>

$ip=$_POST['IP'];
$p = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$";
if ( preg_match( "/[a-zA-Z-_]+/si", $ip ) ){
 $i = gethostbyname( $ip );
 if ( eregi( $p, $i ) ){
  echo "您查询的域名:$ip
IP地址:$i
来自:".ip($i);
 }else{
 }
}else{
 if ( eregi( $p, $ip ) ){
  echo "您查询的IP地址:$ip
来自:".ip($ip);
 }else{
 }
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn