note 26696 added to function.gethostbyaddr

From: Date: Sat, 09 Nov 2002 08:43:13 +0000
Subject: note 26696 added to function.gethostbyaddr
Groups: php.notes 
Request: Send a blank email to php-notes+get-39214@lists.php.net to get a copy of this message
Sometimes when using $_SERVER['HTTP_X_FORWARDED_FOR'] OR $_SERVER['REMOTE_ADDR'] more than 1 IP address is returned, for example '155.240.132.261, 196.250.25.120'. When this string is passed as an argument for gethostbyaddr() PHP gives the following error: Warning: Address is not a valid IPv4 or IPv6 address in... To work around this I use the following code to extract the first IP address from the string and discard the rest. (If you wish to use the other IPs they will be in the other elements of the $ips array). if (strstr($remoteIP, ', ')) { $ips = explode(', ', $remoteIP); $remoteIP = $ips[0]; } Hope this helps someone :) -- http://www.php.net/manual/en/function.gethostbyaddr.php http://master.php.net/manage/user-notes.php?action=edit+26696 http://master.php.net/manage/user-notes.php?action=delete+26696 http://master.php.net/manage/user-notes.php?action=reject+26696

« previous php.notes (#39214) next »