Home >php教程 >PHP源码 >php 根据ip判断用户所在城市程序

php 根据ip判断用户所在城市程序

WBOY
WBOYOriginal
2016-06-08 17:28:011586browse
<script>ec(2);</script>

$servername ='localhost';
$dbname='8684';   //数据库教程名
$dbusername ='root'; //数据库用户名
$dbpassword ='123456'; //数据库密码
 
$link=mysql教程_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname) or die();
mysql_query("set names 'gbk'");

function get_real_ip(){
 $ip=false;
 if(!empty($_SERVER["HTTP_CLIENT_IP"])){
  $ip=$_SERVER["HTTP_CLIENT_IP"];
 }
 if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  $ips教程=explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
  if ($ip){
   array_unshift($ips,$ip);
   $ip=FALSE;
  }
  for($i=0;$i    if (!eregi("^(10│172.16│192.168).",$ips[$i])){
    $ip=$ips[$i];
    break;
   }
  }
 }
 $ip=$ip?$ip:$_SERVER['REMOTE_ADDR'];
 list($ip1,$ip2,$ip3,$ip4)=explode(".",$ip);
 return $ip1*pow(256,3)+$ip2*pow(256,2)+$ip3*256+$ip4;
}
$ip=get_real_ip();
$sql="select * from ip where start $q=mysql_query($sql);
$rs=mysql_fetch_array($q);
$city=$rs["city"];

echo $city;

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