how to find real ip of visitor in php

How to get Real IP from Visitor?

I tried while coding my web application a lot of methods. But found that only way to track real IP of a visitor is :

$_SERVER['REMOTE_ADDR']

If a person is using VPN then there is no way to find his real IP. Whatever method we apply it will always show IP address of the the VPN provider.

If you are going to code Proxy/VPN blocker for your web application then i will suggest to code you script using ” $_SERVER[‘REMOTE_ADDR’] ”  and then check the ip which come through API provided by proxy/vpn detecting sites :

Here is the code which i wrote to find proxy/vpn using iphub.info API

#IP HUB PROXY CHECK#  
function getIpDetails($ip)
{
    global $iphubkey;

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_URL, 'http://v2.api.iphub.info/ip/'.$ip);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Key:'.$iphubkey));
      $result = curl_exec($ch);
      curl_close($ch);
      $obj = json_decode($result, true);
        #IP DETAILS FOR VISITOR#
        $ip = (empty($obj['ip'])) ? '' : $obj['ip'];
        $countryname = (empty($obj['countryName'])) ? '' : $obj['countryName'];
        $proxy = (empty($obj['block']))? '':$obj['block'];
        return $ip.'#'.$countryname.'#'.$proxy;
}

$iphubkey = ” API KEY OF YOUR IPHUB “

So when we use the above function using our iphub API key , it will send us return $ip.’#’.$countryname.’#’.$proxy;

Later break this with explode function and get all 3 values $ip , $countryname , $proxy

Hope this tutorial helps you to solve this issue.

2 thoughts on “How to get Real IP from Visitor?

Leave a Reply

Your email address will not be published. Required fields are marked *

22  ⁄    =  11