PHP programming: cleverly obtain the real IP of website visitors
Author:Eve Cole
Update Time:2009-06-07 15:14:23
It is actually very easy to get the visitor's IP in PHP, but some people use the proxy method to avoid the system and get the real IP. And if an intentional person uses it to attack the website and uses a proxy, the real IP of the visitor can be obtained through detection.
The following program can obtain the real IP:
if (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip=$_SERVER['HTTP_CLIENT_IP'];
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip=$_SERVER['REMOTE_ADDR'];