Jump to content

Gethostbyaddr


Pensive

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.