-4

Possible Duplicate:
Get Country of IP Address with PHP

I want to country name or location based on ip address. I can only show ip address. I am trying so hard but I can't. So please, help me to solve this problem.

<?php

  if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
      $ip=$_SERVER['HTTP_CLIENT_IP'];}
  elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}
  else {
      $ip=$_SERVER['REMOTE_ADDR'];
  }

 ?>
Community
  • 1
  • 1
sumon ahmed
  • 61
  • 1
  • 6

2 Answers2

1

You cannot determine the country or location of an IP address by simple inspection. You can lookup some information about it by sending it to a service like http://whatismyipaddress.com/ip/127.0.0.1 (where the ip address in question replaces 127.0.0.1). That service uses a variety of databases to arrive at a conclusion. It is not definitely correct, but often more correct than not.

wallyk
  • 56,922
  • 16
  • 83
  • 148
0

If you require this functionality for commercial use, the solution is CountryHawk

http://www.cyscape.com/products/chawk/

You can use CountryHawk with PHP, provided you have the ability to run server side ActiveX or JavaBean components from PHP. If you have ActiveX support from within PHP use the ActiveX/.NET version of CountryHawk. Otherwise us the JavaBean version (CountryHawk4J).

Here is a snippet of code which demonstrates how to use CountryHawk from PHP with ActiveX support:

$countryObj = new COM("cyScape.CountryObj");
$countryObj->initialize(@$_SERVER["REMOTE_ADDR"]);
$userCountryCode = $countryObj->CountryCode;
Jason R
  • 1
  • 2