1

I want to get the computer name that access a page. So this question has been asked.

I tested on my localhast,

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $hostname;

I get my computer name, such as,

lau-pc

But when I run this code on my live server, I don't get my computer name, I get ip address instead,

123.136.xxx.xx

how come? So I can't get the computer name from the live server then?

Community
  • 1
  • 1
Run
  • 54,938
  • 169
  • 450
  • 748
  • 3
    According to the documentation gethostbyaddr returns the original ip, if the name resolution failed. You can test your servers settings if you can logon via ssh with a "host 123.136.xxx.xxx" command. Probably there will be some kind of misconfiguration. Otherwise REMOTE_ADDR is not 100% safe. Probably you should not build important logic on it. (REMOTE_ADDR will show the proxies ip address if the client is behind a proxy.) And dns resolution can be painfully slow... Which can be unacceptable in online environmets. – Lajos Veres Sep 29 '13 at 15:20

0 Answers0