i used $_SERVER['REMOTE_ADDR'] and it returns client ip address (IP address from which the user is viewing the current page) but at now (and same code) it returns host ip address (i checked ip address with ip location). problem is with host or what? thank u.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You should query for HTTP_X_FORWARDED_FOR
first and if it isn't assigned use REMOTE_ADDR
.
回答2:
@James @imez
By default the client IP is in $_SERVER['REMOTE_ADDR']. When the user enters your site using a PROXY server (HTTP gateway) it tells you who it's proxing for (HTTP_X_FORWARDED_FOR) and will give it's own Proxy IP in $_SERVER['REMOTE_ADDR'].
Anonymous proxies will omit HTTP_X_FORWARDED_FOR or simply lie to you.
Knowing you have a real client IP isn't possible.
回答3:
I have to mention that the array key is case-sensitive, and should be upper-case:
var_dump($_SERVER['remote_addr']);
echo "\n";
var_dump($_SERVER['REMOTE_ADDR']);
Output:
Notice: Undefined index: remote_addr in /home/adam/public_html/2011/01/04/foo.php on line 3
NULL
string(15) "10.0.1.51"
I would var_dump($_SERVER)
just to evaluate the state of your world, and go from there.