中文字幕在线有码午夜,国产成 人亚洲91,狼狼狼色在线精品视频免费,久久国产厕所拍精品盗摄

    <sub id="gptbo"><ol id="gptbo"></ol></sub>

      <legend id="gptbo"></legend>

        <legend id="gptbo"></legend>

        <sub id="gptbo"><ol id="gptbo"><nobr id="gptbo"></nobr></ol></sub>
        <legend id="gptbo"><u id="gptbo"><thead id="gptbo"></thead></u></legend>
        <sub id="gptbo"><ol id="gptbo"></ol></sub>

        云南網(wǎng)站建設(shè)創(chuàng)新企業(yè) 昆明多彩網(wǎng)絡(luò)公司

        利用百度api方便快速查詢ip歸屬地

        來源:昆明多彩網(wǎng)絡(luò)公司 日期:2011-02-10 閱讀: 發(fā)表評(píng)論

        查詢ip的歸屬地功能一直是程序開發(fā)人員頭疼的事情,以前是利用網(wǎng)絡(luò)上臃腫的ip來得到結(jié)果,現(xiàn)在可以很方便的使用百度的api來實(shí)現(xiàn)。

        在百度api出來之前程序員們一直都是使用臃腫的ip來實(shí)現(xiàn)查詢ip歸屬地的,現(xiàn)在百度的ip查詢API可以快速幫我們實(shí)現(xiàn)這個(gè)目的。

        <?php
        function get_city($ip=null) {
        $ip = ($ip) ? $ip :$_SERVER['REMOTE_ADDR'];
        $url = "http://open.baidu.com/ipsearch/s?wd=$ip&tn=baiduip";
        $res = file_get_contents($url);
        if ( preg_match('#來自:<b>(.+)</b>#Ui', $res, $m) ) {
        return $m[1];
        }
        }
        //使用范例
        $address= get_city("8.8.8.8");  //8.8.8.8是google公司免費(fèi)提供的dns服務(wù)器。
        echo $address;
        ?>

        注意該代碼為php代碼,只適用于小規(guī)模的查詢,一般的用法是第一訪問就取得ip歸屬地,然后存入數(shù)據(jù)庫或者cookie以方便后面使用,這樣就避免了重復(fù)的去訪問百度api地址,以防被百度ban導(dǎo)致獲取ip歸屬地失敗。

        發(fā)表評(píng)論評(píng)論列表(有 條評(píng)論)