note 45850 added to function.getenv

From: Date: Tue, 21 Sep 2004 17:10:38 +0000
Subject: note 45850 added to function.getenv
Groups: php.notes 
Request: Send a blank email to php-notes+get-77112@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.getenv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45850 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45850&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45850&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77112) next »