Advertisement
hexasoft

Credit Card Fraud Prevention Using PHP and MySQL for IPV4

May 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. /****************************************************************************************************************/
  2. /* Description: This snippet is provide simple way to help user Credit Card Fraud Prevention                    */
  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/credit-card-fraud-prevention-using-php-and-mysql-database               */
  6. /****************************************************************************************************************/
  7. /* You can obtain free IP Country database for IPv4 at https://lite.ip2location.com/database/ip-country         */
  8. /* You can obtain free country information data at https://www.ip2location.com/free/country-information         */
  9.  
  10. <?php
  11.         // country in billing address, in this example, we assigned "US" for United States.
  12.         $billingCountrySHORT = "US";
  13.  
  14.         // Replace this MYSQL server variables with actual configuration
  15.         $mysql_server = "localhost";
  16.         $mysql_user_name = "root";
  17.         $mysql_user_pass = "";
  18.  
  19.         // Retrieve visitor IP address from server variable REMOTE_ADDR
  20.         $ipaddress = $_SERVER['REMOTE_ADDR'];
  21.  
  22.         // Convert IP address to IP number for querying database
  23.         $ipno = Dot2LongIP($ipaddress);
  24.  
  25.         // Connect to the database server
  26.         $link = mysqli_connect($mysql_server, $mysql_user_name, $mysql_user_pass) or die("Could not connect to MySQL database");
  27.  
  28.         // Connect to the IP2Location database
  29.         mysqli_select_db($link,"ip2location") or die("Could not select database");
  30.  
  31.         // SQL query string to match the recordset that the IP number fall between the valid range
  32.         $query = "SELECT * FROM ip_country WHERE $ipno <= ip_to LIMIT 1";
  33.                
  34.         // Execute SQL query
  35.         $result = mysqli_query($link,$query) or die("IP2Location Query Failed");
  36.  
  37.         // Retrieve the recordset (only one)
  38.         $row = mysqli_fetch_assoc($result);
  39.            
  40.         // Keep the country information into two different variables
  41.         $country_code = $row['country_code'];
  42.         $country_name = $row['country_name'];
  43.          
  44.  
  45.         // Free recordset and close database connection
  46.         mysqli_free_result($result);
  47.         mysqli_close($link);
  48.  
  49.          if ($country_code == $billingCountrySHORT) {
  50.             // IP address same as country in billing address: Low Fraud Risk
  51.             echo "Low Frauk Risk ";
  52.           } else {                
  53.             // IP address different from country in billing address: High Fraud Risk
  54.             echo"High Fraud risk";
  55.           }
  56.  
  57.         exit;
  58.  
  59.         // Function to convert IP address (xxx.xxx.xxx.xxx) to IP number (0 to 256^4-1)
  60.         function Dot2LongIP ($IPaddr)
  61.         {
  62.           if ($IPaddr == "") {
  63.           return 0;
  64.         } else {
  65.         $ips = explode(".", "$IPaddr");
  66.         return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
  67.          }
  68.         }
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement