, , ,

I tried to find out a solution how we can block or trace visitor location and based on that location we do some action

First you have to use 3rd party api to get visitor location. The following url will give you the detail.

Lets assume the visitor ip is (you’ll get key from that website)

Its has some response format that is xml, json, raw, just you have to pass a get variable &format=json

  if (getenv(HTTP_X_FORWARDED_FOR)){
        $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
        $ipaddress = getenv(REMOTE_ADDR);
        //echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ;
    } else {
        $ipaddress = getenv(REMOTE_ADDR);
        //echo "Your IP address is : $ipaddress";


$_API = "83838s88s4e0a65jhk80246d77d8s5s3988d9fb1asdkf000asd8fslasdlfasdf6s9sce";
$_URL = "http://api.ipinfodb.com/v3/ip-country/?key=$_API&ip=$ipaddress&format=json";

$data = file_get_contents($_URL);

$data = json_decode($data);
if(isset($data->statusCode) && $data->statusCode == "OK"){
    if(isset($data->countryCode) && ($data->countryCode != "USA" )) || $data->countryCode != "BD")){

In this way we can find out the country, city, post code, time zone etc. we can block or trace visitors in our website.