zoukankan      html  css  js  c++  java
  • php对ip地址的处理

        public function actions()
        {
            $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".self::ip();
            $str = self::sendCurl('http://pv.sohu.com/cityjson');
            echo '<pre>';
            print_r($url);die;
            $str1= explode('{"cip": "',$str);
            $str2=(explode('", "cid":',$str1['1']));
            $last = $str2['0'];
            echo $str;die;
    
            exit(json_encode(['resCode' => 404, 'resMsg' => '接口错误']));
        }
        public static function sendCurl($url = '', $data = [])
        {
            $ch = curl_init();
            //设置选项,包括URl
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1); //post数据
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //post的变量
            //执行并获取内容
            $info = curl_exec($ch);
            curl_close($ch);
    
            return $info;
        }
    
        public static  function ip() {
            if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
                $ip = getenv('HTTP_CLIENT_IP');
            } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
                $ip = getenv('HTTP_X_FORWARDED_FOR');
            } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
                $ip = getenv('REMOTE_ADDR');
            } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
                $ip = $_SERVER['REMOTE_ADDR'];
            }
            $res =  preg_match ( '/[d.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
            return $res;
        }
  • 相关阅读:
    strongswan--HA
    RFC8221 -- 密码算法实现要求和使用指南
    strongswan--ikev2软件架构
    strongswan--ike sa状态机
    strongswan--ipsec.conf配置文件分析
    strongswan--linux内核ipsec policy类型
    strongswan--配置Charon-systemd问题解决
    strongswan——IKE建立过程
    GCC入门
    MPLS-TP OAM各个层次
  • 原文地址:https://www.cnblogs.com/ghjbk/p/10063786.html
Copyright © 2011-2022 走看看