note 45850 deleted from function.getenv by bjori

From: Date: Sat, 25 Mar 2006 11:02:13 +0000
Subject: note 45850 deleted from function.getenv by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106581@lists.php.net to get a copy of this message
Note Submitter: NOdonn [AT] edonn . comSPAM ---- I am not sure if this is obvious or not, but besides filtering LAN addresses, you can also filter proxies as well. When I switched servers from one based in Singapore to one based in the United States, my IP-detection script (using the basic $_SERVER['REMOTE_ADDR']) started returning 165.21.*.* for all Singaporean users, as they had to go through our ISP's proxy. Below is the script I use to get IP addresses of Singaporean internet users (based on code I saw on from some other people's contributions here): <?php function convertIp($originalIp) { $ipParts = explode(".", $originalIp); if ($ipParts[0] == "165" && $ipParts[1] == "21") { if (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } elseif (getenv("REMOTE_ADDR")) { $ip = getenv("REMOTE_ADDR"); } } else { return $originalIp; } return $ip; } ?> It is very basic, but gets the job done for my mostly Singaporean visitors.

« previous php.notes (#106581) next »