hexasoft icon

Display Visitor's Proxy Using IP2Proxy Web Service

hexasoft | PRO | 05/16/18 09:05:50 AM UTC | 0 ⭐ | 526 👁️ | Never ⏰ | []
PHP |

2.5 KB

|

None

|

0 👍

/

0 👎

/********************************************************************************************************************/
/* Description: This snippet is provide simple way to help user display Visitor's Proxy Used IP2Proxy Web Service.  */
/*              suggestions for different city locations across the country.                                        */
/*              There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at:      */
/*https://www.ip2location.com/tutorials/display-visitors-proxy-using-ip2proxy-web-service                           */          
/********************************************************************************************************************/
 
<?php
 $host= gethostname();
 $ipAddress = gethostbyname($host);
 $urlTemplate = 'http://api.ip2proxy.com/?ip=' . $ipAddress .  '&key=demo&package=PX4';
 
 // replace the "%s" with real IP address
 $urlToCall = sprintf( $urlTemplate, $ipAddress);
 
 $rawJson = file_get_contents( $urlToCall );
 
 $proxy = json_decode( $rawJson, true );
 
 if(isset($proxy['cityName'])){
 
    if($proxy['cityName']=="-"){
        echo '<center>You are in local server!</center><br>';
        echo '<script language="javascript">';
        echo 'alert("You are in local server!")';
        echo '</script>';
    }
}else{
    echo 'IP Address parsing error!';
}
?>
<html>
<head>
<title>IP2Proxy Web Service</title>
</head>
<body>
<div>
<center><a href="https://www.ip2location.com/ip2proxy-web-service">IP2Proxy Web Service</a></center><br>
 
</div>
<div>
<center>Your IP address <?php echo $ipAddress; ?></center>
      <center>
      <?php
      if(isset($proxy['response'])&&isset($proxy['countryCode'])&&isset($proxy['countryName'])&&isset($proxy['regionName'])&&isset($proxy['cityName'])&&isset($proxy['isp'])&&isset($proxy['isProxy'])&&isset($proxy['proxyType'])){
        echo '<br>Response:'."\n". $proxy['response'] . "\n<br>";
        echo 'Country Code:'."\n". $proxy['countryCode'] . "\n<br>";
        echo 'Country Name:'."\n". $proxy['countryName'] . "\n<br>";
        echo 'Region Name:'."\n". $proxy['regionName'] . "\n<br>";
        echo 'City Name:'."\n". $proxy['cityName'] . "\n<br>";
        echo 'Internet Service Provider:'."\n". $proxy['isp'] . "\n<br>";
        echo 'Is Proxy:'."\n". $proxy['isProxy'] . "\n<br>";
        echo 'Proxy Type:'."\n". $proxy['proxyType'] . "\n<br>";
      }else{
          echo 'IP Address parsing error!';
      }
      ?>
      </center>
</div>
</body>
</html>

Comments