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

WBOY
Libérer: 2016-07-29 08:54:29
original
2603 Les gens l'ont consulté

<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>
Copier après la connexion
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了通过ip地址判断所在区域,包括了ip地址,判断方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!