| | |
PHP - Converting IP to Country
![]() |
PHP - Converting IP to Country
Hello,
Is there any function/pre-made scripts in php which can tell me the name of country based on IP?
For example: If I supply an IP 132.162.138.139 then the script would echo "India"
Thanx in advance
Hello,
Is there any function/pre-made scripts in php which can tell me the name of country based on IP?
For example: If I supply an IP 132.162.138.139 then the script would echo "India"
Thanx in advance
Heres a search for it on sourceforge.
http://sourceforge.net/search/?type_...to+country+php
There are a number of IP to country scripts in PHP there..
What to note is that differnet scripts use different IP to Address databases. Some are better than others.
If you're interested in writing your own, you can download a database from sourceforge, or http://www.hostip.info for example..
Then use it to get the country from the IP.
Another way is to use a webservice.
For instance you can use this one:
http://www.hostip.info/use.html
To get the country would be:
http://api.hostip.info/country.php?ip=$IP
Where $IP is the user IP.
PHP would look something like:
[php]
<?php
$country = '';
$IP = $_SERVER['REMOTE_ADDR'];
if (!empty($IP)) {
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP);
}
?>
[/php]
http://sourceforge.net/search/?type_...to+country+php
There are a number of IP to country scripts in PHP there..
What to note is that differnet scripts use different IP to Address databases. Some are better than others.
If you're interested in writing your own, you can download a database from sourceforge, or http://www.hostip.info for example..
Then use it to get the country from the IP.
Another way is to use a webservice.
For instance you can use this one:
http://www.hostip.info/use.html
To get the country would be:
http://api.hostip.info/country.php?ip=$IP
Where $IP is the user IP.
PHP would look something like:
[php]
<?php
$country = '';
$IP = $_SERVER['REMOTE_ADDR'];
if (!empty($IP)) {
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP);
}
?>
[/php]
Last edited by digital-ether; May 11th, 2007 at 7:43 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Jul 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Heres a search for it on sourceforge.
http://sourceforge.net/search/?type_...to+country+php
There are a number of IP to country scripts in PHP there..
What to note is that differnet scripts use different IP to Address databases. Some are better than others.
If you're interested in writing your own, you can download a database from sourceforge, or http://www.hostip.info for example..
Then use it to get the country from the IP.
Another way is to use a webservice.
For instance you can use this one:
http://www.hostip.info/use.html
To get the country would be:
http://api.hostip.info/country.php?ip=$IP
Where $IP is the user IP.
PHP would look something like:
[php]
<?php
$country = '';
$IP = $_SERVER['REMOTE_ADDR'];
if (!empty($IP)) {
$country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP);
}
?>
[/php]
![]() |
Similar Threads
- customized right-click menu based on id (JavaScript / DHTML / AJAX)
- IP-to-Country converter (php script) (PHP)
- Converting Access Forms to PHP Forms (PHP)
- PHP email problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: Testing PHP + cURL code offline/non-hosted site?
- Next Thread: error with base64_decode returning the data instead of the images
Views: 11877 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api archive array arrays beginner binary broken cakephp checkbox class classes cms code combobox cron curl database date development directory display dropdown dynamic echo email error file files folder form forms function functions header hosting htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio recursion regex remote rewrite script search select server sessions sms soap source space speed sql storage syntax table update updates upload url user validation validator variable video web xml youtube






