3

Why does gethostbyaddr($_SERVER['REMOTE_ADDR']) return an IP address as opposed to a computer name as it should. It works as intended on 50 computers here in the office and returns the computer name. At the moment it returns an IP address on my own computer when it should return a computer name.

Is there a quick fix for this?

David Egan
  • 424
  • 2
  • 8
  • 23

2 Answers2

2

From the documentation:

gethostbyaddr — Get the Internet host name corresponding to a given IP address

The important part is Internet, what PHP do is a DNS lookup. At your office your roouter may make a DNS resolve for local machines, but your home is not registered on any DNS.

For depending of your need your could use : How can I read the client's machine/computer name from the browser?

But this is not something easy to do.

Community
  • 1
  • 1
Larandar
  • 132
  • 1
  • 10
  • When I refer to my own computer, I am talking about my office computer. The computer I use at work. – David Egan May 11 '17 at 12:35
  • OK, but in any case it work for the other computer because the DNS is resolved for those name. Most likely either by the router or a hosts file. But from my understanding of the documention this function is not intended for what you think, it should get you a DNS name not ComputerName, and work for 50 computer because both are resolved the same way IN YOUR OFFICE. – Larandar May 11 '17 at 14:22
0

Now as the original question points out the offending machine above operates in a intranet environment within our company. Now the solution to this problem was that IT in the company had to re-join the offending machine in this case my work computer to the domain and then run group policy. That fixed it for me on two different machines on the same intranet. This situation does not happen a lot but our IT were in the past perplexed for a solution. The above actions reverted the IP to the required machine name.

David Egan
  • 424
  • 2
  • 8
  • 23
  • Larandar's answer exactly pinpoints the root of your problem and led you to solving the problem the right way, although that problem is really specific to your case. Please, consider accepting either his answer, or the one of your own. – Eduard Sukharev Aug 03 '21 at 13:59