透過ip位址判斷所在區域 ip位址判斷正誤 ip位址如何判斷正誤 怎麼判斷ip位址類

WBOY
發布: 2016-07-29 08:54:29
原創
2625 人瀏覽過

<code><span>//获取用户真实IP</span>
    public function get_client_ip() {
        <span>if</span> (<span>getenv</span>(<span>"HTTP_CLIENT_IP"</span>) && strcasecmp(<span>getenv</span>(<span>"HTTP_CLIENT_IP"</span>), <span>"unknown"</span>))
            <span>$ip</span> = <span>getenv</span>(<span>"HTTP_CLIENT_IP"</span>);
        <span>else</span><span>if</span> (<span>getenv</span>(<span>"HTTP_X_FORWARDED_FOR"</span>) && strcasecmp(<span>getenv</span>(<span>"HTTP_X_FORWARDED_FOR"</span>), <span>"unknown"</span>))
            <span>$ip</span> = <span>getenv</span>(<span>"HTTP_X_FORWARDED_FOR"</span>);
        <span>else</span><span>if</span> (<span>getenv</span>(<span>"REMOTE_ADDR"</span>) && strcasecmp(<span>getenv</span>(<span>"REMOTE_ADDR"</span>), <span>"unknown"</span>))
            <span>$ip</span> = <span>getenv</span>(<span>"REMOTE_ADDR"</span>);
        <span>else</span><span>if</span> (isset (<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]) && <span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>] && strcasecmp(<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>], <span>"unknown"</span>))
            <span>$ip</span> = <span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>];
        <span>else</span><span>$ip</span> = <span>"unknown"</span>;
        <span>return</span> (<span>$ip</span>);
    }

    <span>// 调用get_client_ip方法</span><span>$ip</span> = <span>$this</span>->get_client_ip();
    <span>// 调用淘宝接口</span><span>$url</span> = <span>"http://ip.taobao.com/service/getIpInfo.php?ip="</span>.<span>$ip</span>;
    <span>$dip</span> = file_get_contents(<span>$url</span>);
    <span>$dd</span> = json_decode(<span>$dip</span>,true);
    var_dump(<span>$dd</span>);</code>
登入後複製
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了透過ip位址判斷所在區域,包括了ip位址,判斷方面的內容,希望對PHP教學有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板