Maison > Article > développement back-end > 通过ip地址判断所在区域 ip地址判断正误 ip地址如何判断正误 怎么判断ip地址类
<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教程有兴趣的朋友有所帮助。