V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
sida
V2EX  ›  PHP

菜鸟提问关于获取用户真实 ip 的问题

  •  
  •   sida · Aug 12, 2018 · 3309 views
    This topic created in 2820 days ago, the information mentioned may be changed or developed.

    代码 1#$ip = $_SERVER["REMOTE_ADDR"]; 代码 2$api = "http://ip.taobao.com/service/getIpInfo.php?ip=myip"; //初始化     $curl = curl_init();     //设置抓取的 url     curl_setopt($curl, CURLOPT_URL, $api);     //设置获取的信息以文件流的形式返回,而不是直接输出。     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);     //执行命令     $data = curl_exec($curl);     //关闭 URL 请求     curl_close($curl);     //显示获得的数据

    $str=$data; $t1 = mb_strpos($str,'ip":"'+1); $t2 = mb_strpos($str,'","country'); $ip = mb_substr($str,$t1,$t2-$t1); echo $ip; 返回结果一致 通过 api 提交阿里云修改域名解析 前者可以通过后者则提示 The DNS record is invalid or in the wrong format.求大神解答

    3 replies    2018-08-13 02:10:57 +08:00
    rubycedar
        1
    rubycedar  
       Aug 12, 2018 via iPhone
    应该是构造的数据格式有问题,看看接口文档。
    sida
        2
    sida  
    OP
       Aug 12, 2018
    @rubycedar 我在调试过程中返回的数据格式都是一致的就是不知道为什么提交不上去
    ysc3839
        3
    ysc3839  
       Aug 13, 2018 via Android
    贴一下提交的数据。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2506 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 06:44 · PVG 14:44 · LAX 23:44 · JFK 02:44
    ♥ Do have faith in what you're doing.