<code><span>// 获取IP地址</span> function GetIP() { <span>if</span>(<span>getenv</span>(<span>'HTTP_CLIENT_IP'</span>) && strcasecmp(<span>getenv</span>(<span>'HTTP_CLIENT_IP'</span>), <span>'unknown'</span>)) { <span>$thisip</span> = <span>getenv</span>(<span>'HTTP_CLIENT_IP'</span>); } elseif(<span>getenv</span>(<span>'HTTP_X_FORWARDED_FOR'</span>) && strcasecmp(<span>getenv</span>(<span>'HTTP_X_FORWARDED_FOR'</span>), <span>'unknown'</span>)) { <span>$thisip</span> = <span>getenv</span>(<span>'HTTP_X_FORWARDED_FOR'</span>); } elseif(<span>getenv</span>(<span>'REMOTE_ADDR'</span>) && strcasecmp(<span>getenv</span>(<span>'REMOTE_ADDR'</span>), <span>'unknown'</span>)) { <span>$thisip</span> = <span>getenv</span>(<span>'REMOTE_ADDR'</span>); } elseif(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>$thisip</span> = <span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]; } preg_match(<span>"/[\d\.]{7,15}/"</span>, <span>$thisip</span>, <span>$thisips</span>); <span>$thisip</span> = <span>$thisips</span>[<span>0</span>] ? <span>$thisips</span>[<span>0</span>] : <span>'unknown'</span>; <span>return</span><span>$thisip</span>; }</code>
已经测试过了。可以获取到真实的IP地址!TCP/IPv4
可以直接放代码里用就行了 。不用谢。请叫我‘雷锋’
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });以上就介绍了无法获取ip地址 PHP获取准确的IP地址的方法,包括了无法获取ip地址方面的内容,希望对PHP教程有兴趣的朋友有所帮助。