通过ip地址判断所在区域 ip地址判断正误 ip地址如何判断正误 怎么判断ip地址类

WBOY
发布: 2016-07-29 08:54:29
原创
2616 人浏览过

<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
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板