Pensive Posted September 2, 2007 Share Posted September 2, 2007 I piggy back on another domain and when they switched to Dreamhost, they had to change how my website was handled. It went from www.xxx.com/mywebsite to mywebsite.xxx.com. As a result of this the gethostbyaddr command in one of my web pages generates the following error: Warning: gethostbyaddr() [function.gethostbyaddr]: Address is not a valid IPv4 or IPv6 address Does anybody have any suggestions as to a solution. Thanks. Link to comment https://forums.phpfreaks.com/topic/67608-gethostbyaddr/ Share on other sites More sharing options...
pocobueno1388 Posted September 2, 2007 Share Posted September 2, 2007 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 Came from this page: http://php.net/function.gethostbyaddr Link to comment https://forums.phpfreaks.com/topic/67608-gethostbyaddr/#findComment-339635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.