Advertisement
hexasoft

How to lookup for proxy record using PHP and MySQL for IPV4

May 16th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. /****************************************************************************************************************/
  2. /* Description: This snippet is provide simple way to show user on how to lookup for a proxy record.            */
  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/how-to-lookup-for-proxy-record-using-php-and-mysql                      */
  6. /****************************************************************************************************************/
  7. /* You can obtain to setup the proxy database for IPv4 at:                                                      */
  8. /* https://lite.ip2location.com/database/px4-ip-proxytype-country-region-city-isp                               */
  9.  
  10. <?php
  11.     //Open connection to mysql server
  12.     $mysqli = new mysqli('localhost', 'root', '', 'ip2location');
  13.  
  14.     //Check connection
  15.     if ($mysqli->connect_errno) {
  16.         printf("Connect failed: %s\n", $mysqli->connect_error);
  17.         exit();
  18.     }
  19.  
  20.     //Check if the IP address is a proxy address
  21.     $ip_address = '4.0.0.37';
  22.     $result = $mysqli->query('SELECT * FROM ip2proxy_px4 WHERE inet_aton("' . $ip_address . '") between ip_from AND ip_to LIMIT 1');
  23.  
  24.     if ($result->num_rows > 0){
  25.         //proxy
  26.         $row = $result->fetch_assoc();
  27.         echo 'IP Address: ' . $ip_address . '<br>';
  28.         echo 'Proxy Type: ' . $row['proxy_type'] . '<br>';
  29.         echo 'Country Code: ' . $row['country_code'] . '<br>';
  30.         echo 'Country Name: ' . $row['country_name'] . '<br>';
  31.         echo 'Region Name: ' . $row['region_name'] . '<br>';
  32.         echo 'City Name: ' . $row['city_name'] . '<br>';
  33.         echo 'ISP: ' . $row['isp'] . '<br>';
  34.     }
  35.     else{
  36.         //non-proxy
  37.         echo $ip_address . ' is not a proxy<br>';
  38.     }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement