In my application after entering the domain name in a text field I want to auto populate the domain's IP and Country.
Asked
Active
Viewed 2,328 times
2
-
1to 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 Answers
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
-
how can i solve the error Call to undefined function geoip_country_name_by_name() – Jun 29 '13 at 05:26
-
@SekharSeerapu, seems like you haven't included the libraries of geoip. – Shankar Narayana Damodaran Jun 29 '13 at 05:30
-
-
@SekharSeerapu, you need to install the PECL extension in PHP. It will work fine after you do that. Here's the link http://www.php.net/manual/en/geoip.installation.php – Shankar Narayana Damodaran Jun 29 '13 at 05:39
-
@SekharSeerapu, Why you keep switching your mind ? Did you try installing PECL ? That will solve your issue. If you face anything let us know we are here to help. – Shankar Narayana Damodaran Jun 29 '13 at 14:49
-
hey i already downloaded the files and added to my folder.It gives me the IP address but not country..I don,t know what is the problem.Please help me – Jun 29 '13 at 18:29