Advertisement
hexasoft

Display Visitor's Proxy Using IP2Proxy Web Service

May 16th, 2018
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. /********************************************************************************************************************/
  2. /* Description: This snippet is provide simple way to help user display Visitor's Proxy Used IP2Proxy Web Service.  */
  3. /*              suggestions for different city locations across the country.                                        */
  4. /*              There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at:      */
  5. /*https://www.ip2location.com/tutorials/display-visitors-proxy-using-ip2proxy-web-service                           */         
  6. /********************************************************************************************************************/
  7.  
  8. <?php
  9.  $host= gethostname();
  10.  $ipAddress = gethostbyname($host);
  11.  $urlTemplate = 'http://api.ip2proxy.com/?ip=' . $ipAddress .  '&key=demo&package=PX4';
  12.  
  13.  // replace the "%s" with real IP address
  14.  $urlToCall = sprintf( $urlTemplate, $ipAddress);
  15.  
  16.  $rawJson = file_get_contents( $urlToCall );
  17.  
  18.  $proxy = json_decode( $rawJson, true );
  19.  
  20.  if(isset($proxy['cityName'])){
  21.  
  22.     if($proxy['cityName']=="-"){
  23.         echo '<center>You are in local server!</center><br>';
  24.         echo '<script language="javascript">';
  25.         echo 'alert("You are in local server!")';
  26.         echo '</script>';
  27.     }
  28. }else{
  29.     echo 'IP Address parsing error!';
  30. }
  31. ?>
  32. <html>
  33. <head>
  34. <title>IP2Proxy Web Service</title>
  35. </head>
  36. <body>
  37. <div>
  38. <center><a href="https://www.ip2location.com/ip2proxy-web-service">IP2Proxy Web Service</a></center><br>
  39.  
  40. </div>
  41. <div>
  42. <center>Your IP address <?php echo $ipAddress; ?></center>
  43.       <center>
  44.       <?php
  45.       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'])){
  46.         echo '<br>Response:'."\n". $proxy['response'] . "\n<br>";
  47.         echo 'Country Code:'."\n". $proxy['countryCode'] . "\n<br>";
  48.         echo 'Country Name:'."\n". $proxy['countryName'] . "\n<br>";
  49.         echo 'Region Name:'."\n". $proxy['regionName'] . "\n<br>";
  50.         echo 'City Name:'."\n". $proxy['cityName'] . "\n<br>";
  51.         echo 'Internet Service Provider:'."\n". $proxy['isp'] . "\n<br>";
  52.         echo 'Is Proxy:'."\n". $proxy['isProxy'] . "\n<br>";
  53.         echo 'Proxy Type:'."\n". $proxy['proxyType'] . "\n<br>";
  54.       }else{
  55.           echo 'IP Address parsing error!';
  56.       }
  57.       ?>
  58.       </center>
  59. </div>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement