2

In my application after entering the domain name in a text field I want to auto populate the domain's IP and Country.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    to use geoip_country_name_by_name() you need the PECL extension, have a look here http://www.php.net/manual/en/geoip.installation.php – Afsar Jun 29 '13 at 05:37
  • Note that that's not necessarily possible by definition. Do you have any idea how many servers there are worldwide for google.com? – deceze Jun 29 '13 at 06:56
  • @Zan, if i want to get country name what code should i add to my file and what are necessary files –  Jun 29 '13 at 07:27

1 Answers1

2

Make use of gethostbyname() (returns a single IP) and gethostbynamel() gives you a list of IP addresses associated with the hostname.

Here's an example.

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

Regarding grabbing country information, you need a 3rd party solution.

BestPractices
  • 12,738
  • 29
  • 96
  • 140
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126