How to show an IP address ??

A

Anonymous

Guest
Helo guys,

I have a php script like :
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $hostname;
?>

When it runs on a local server, it shows IP : localhost

But the problem is, when i upload the file, it shows IP : ws132018.corporate-access.com

Why is different? And what IP address (ws132018.corporate-access.com) is it?

Can u give me a better solution? Thx b4.
 
$_SERVER['REMOTE_ADDR'] is the IP address.

gethostbyaddr($_SERVER['REMOTE_ADDR']) finds the hostname for that IP address. In case of localhost, that's retrieved from the hostfile. For the second, it can't find it in the hostfile and uses a DNS query to resolve it.

ws132018.corporate-access.com is the name for that IP address, which is normally an identifier for the ISP. In this case the ISP is PCCW Global (http://www.corporate-access.com).

Coditor
 
Back
Top