function GetIP()
    {
        $cip = "";
        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
           $cip = $_SERVER["HTTP_CLIENT_IP"];
        }
        if(!empty($_SERVER["REMOTE_ADDR"])){
           $cip = $_SERVER["REMOTE_ADDR"];
        }
        if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
           $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }
        return $cip;
    }
    $ch = curl_init();
    $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.GetIP();
    $json = file_get_contents($url);
    $ip_data = json_decode($json, true);
    /*$header = array(
        'apikey:a49f5d21a5deead357e9faf3895f0907',
    );
    // 添加apikey到header
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 执行HTTP请求
    curl_setopt($ch , CURLOPT_URL , $url);
    $res = curl_exec($ch);
    $ip_data = json_decode($res,true);*/
    $ipaddress = $ip_data['retData']['province'].$ip_data['retData']['city'];
    if(strpos($ipaddress,'北京')===false){
        header("Location:index(tuibeifen).php");
    }

 推荐:

 

<?php
    function GetIP()
    {
        $cip = "";
        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
           $cip = $_SERVER["HTTP_CLIENT_IP"];
        }
        if(!empty($_SERVER["REMOTE_ADDR"])){
           $cip = $_SERVER["REMOTE_ADDR"];
        }
        if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
           $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }
        return $cip;
    }
    $ch = curl_init();
    $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.GetIP();
    $json = file_get_contents($url);
    $ip_data = json_decode($json, true);
    /*$header = array(
        'apikey:a49f5d21a5deead357e9faf3895f0907',
    );
    // 添加apikey到header
    curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 执行HTTP请求
    curl_setopt($ch , CURLOPT_URL , $url);
    $res = curl_exec($ch);
    $ip_data = json_decode($res,true);*/
    $ipaddress = $ip_data['province'].$ip_data['city'];
    if(strpos($ipaddress,'北京')===false){
        header("Location:../huangheban/index.php");
    }
?>

 

相关文章:

  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2021-12-03
  • 2021-10-19
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2021-05-17
  • 2022-12-23
  • 2018-03-30
  • 2021-06-08
相关资源
相似解决方案