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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:28:011612Durchsuche
<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;

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn