zoukankan      html  css  js  c++  java
  • 根据不同ip进入不同页面

    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");
        }
    ?>
  • 相关阅读:
    poj2386 Lake Counting
    poj 1852 Ants
    Luogu P2419 [USACO08JAN]牛大赛Cow Contest
    Luogu P2336 [SCOI2012]喵星球上的点名
    Luogu P2463 [SDOI2008]Sandy的卡片
    Luogu P2852 [USACO06DEC]牛奶模式Milk Patterns
    Luogu P4248 [AHOI2013]差异
    【NOI2008】志愿者招募
    Luogu P2743 [USACO5.1]乐曲主题Musical Themes
    P3723 [AH2017/HNOI2017]礼物
  • 原文地址:https://www.cnblogs.com/wangjiayi/p/5680376.html
Copyright © 2011-2022 走看看