Sandeep590 Posted August 31, 2016 Share Posted August 31, 2016 Hello Everyone, I have an issue with gethostbyaddr method as it returns an IP address instead of hostname. However , this issue is not seen on all the computers. For example , I see the gethostbyaddr returning the hostname in my machine where as on other systems , it returns the IP address which is incorrect. Can anyone tell me what would be the reason behind it ? echo $_SERVER['REMOTE_ADDR'] returns the IP address of the machine currently logged in whereas $computer_name = substr(gethostbyaddr($_SERVER['REMOTE_ADDR']),0,12) returns the hostname for certain PCs and IP address for other PCs. Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/ Share on other sites More sharing options...
ginerjm Posted August 31, 2016 Share Posted August 31, 2016 While this is not an answer your question is describing expected behavior or this function. Check the manual. Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536906 Share on other sites More sharing options...
Sandeep590 Posted August 31, 2016 Author Share Posted August 31, 2016 I dint get what you said !! I have referred in the manual and I don't find answer in it That's the reason I have posted in this forum Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536908 Share on other sites More sharing options...
ginerjm Posted August 31, 2016 Share Posted August 31, 2016 the manual just points out that the behavior is to be expected. It's not the fault of the function. Did you check that the address you are providing is proper? It does mention invalid input being a problem in the examples. Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536909 Share on other sites More sharing options...
Sandeep590 Posted August 31, 2016 Author Share Posted August 31, 2016 Oh .. ok !! The IP address is provided through php environment variable $_SERVER['REMOTE_ADDR'] and it returns the correct ip address Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536910 Share on other sites More sharing options...
ginerjm Posted August 31, 2016 Share Posted August 31, 2016 Not sure what you are looking for. What 'name' are you seeking? Are you looking for a server's domain name perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536911 Share on other sites More sharing options...
kicken Posted September 1, 2016 Share Posted September 1, 2016 Not all IP addresses have a host name. In those cases, the function just returns the original IP address. Quote Link to comment https://forums.phpfreaks.com/topic/302052-issue-with-gethostbyaddr/#findComment-1536952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.