Determine the area by IP address. Determine the correctness of the IP address. How to judge the correctness of the IP address. How to judge the IP address type.

WBOY
Release: 2016-07-29 08:54:29
Original
2580 people have browsed it

<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>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces how to determine the area by IP address, including IP address and determination. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!