1 /**2 * Get client IP3 */4 functionGetclientip () {5 $ip= ' Unknown ';6 $unknown= ' Unknown ';7 8 if(isset($_server[' Http_x_forwarded_for ']) &&$_server[' Http_x_forwarded_for '] &&strcasecmp($_server[' Http_x_forwarded_for '],$unknown)) {9 //use of transparent proxies, deceptive proxiesTen $ip=$_server[' Http_x_forwarded_for ']; One A}ElseIf(isset($_server[' REMOTE_ADDR ']) &&$_server[' REMOTE_ADDR '] &&strcasecmp($_server[' REMOTE_ADDR '],$unknown)) { - //absence of agents, use of ordinary anonymous agents and high stealth agents - $ip=$_server[' REMOTE_ADDR ']; the } - - //handling multi-tier proxies - if(Strpos($ip, ', ')!==false) { + //Output First IP - $ip=Reset(Explode(‘,‘,$ip)); + } A at return $ip; -}
which
One, not using the proxy server PHP to obtain the client IP situation:
REMOTE_ADDR
= Client IP
HTTP_X_FORWARDED_FOR
= no value or no display
Second, the use of transparent proxy server situation:
REMOTE_ADDR
= Last Proxy Server IP
HTTP_X_FORWARDED_FOR
= Client Real IP (after multiple proxy servers, this value is similar to: 221.) 5. 252. 160, 203. 98. 182. 163, 203. 129. 72. 215)
This kind of proxy server still sends the client's real IP to the Access object, it can't achieve the purpose of hiding the real identity.
Third, the use of ordinary anonymous proxy server PHP to obtain the client IP situation
REMOTE_ADDR
= Last Proxy Server IP
HTTP_X_FORWARDED_FOR
= Proxy Server IP (this value is similar when multiple proxy servers are passed: 203.) 98. 182. 163, 203. 98. 182. 163, 203. 129. 72. 215)
In this case, the real IP of the client is hidden, but the Access object is disclosed to the client using a proxy server to access them.
Iv. use of deceptive proxy servers
REMOTE_ADDR
= Proxy Server IP
HTTP_X_FORWARDED_FOR
= Random IP (after multiple proxy servers, this value is similar to: 220. 4. 251. 159, 203. 98. 182. 163, 203. 129. 72. 215)
This situation also revealed that the client was using a proxy server, but fabricated a bogus random IP (220. 4. 251. 159) Instead of the client's real IP to deceive it.
V. Use of high anonymous proxy server PHP to obtain client IP conditions
REMOTE_ADDR
= Proxy Server IP
HTTP_X_FORWARDED_FOR
= no value or no display
Either REMOTE_ADDR
or HTTP_FORWARDED_FOR
not, these header messages may not be available because different browsers for different network devices might send different IP header messages. Therefore $_SERVER["REMOTE_ADDR"]
, the value that PHP uses and $_SERVER["HTTP_X_FORWARDED_FOR"]
gets may be a null value or a value of " unknown
".
PHP Get client IP