Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.03 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. $offer_id = 4;
  15.  
  16. $url = "";
  17. $host = '185.203.118.216';
  18. $db   = 'bptest';
  19. $user = 'root';
  20. $pass = 'EdQe4ud06H';
  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. $a = $pdo->prepare('select * from ip_blacklist where ip = :ip limit 1');
  40.             $a->bindParam(':ip', $ip);
  41.            
  42.             $a->execute();
  43.  
  44.  
  45.  
  46. if ($a->rowCount() > 0)
  47. {
  48.     //count++
  49.      header('Location: http://yandex.com/');
  50.     exit;
  51. }
  52.  
  53.  
  54. $b = $pdo->prepare('select * from `hits` where ip = :ip limit 1');
  55.             $b->bindParam(':ip', $ip);
  56.            
  57.             $b->execute();
  58.  
  59.  
  60.  
  61. if ($b->rowCount() > 0)
  62. {
  63.     $date = date("Y-m-d H:i:s");
  64.         $s = $pdo->prepare('insert into ip_blacklist (ip, hit_count) values (:ip, 0)');
  65.             $s->bindParam(':ip', $ip);
  66.            
  67.            
  68.             $s->execute();
  69.            
  70.              header('Location: http://yandex.com/');
  71.            
  72.            
  73.     exit;
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  $instance = \TorDetect\TorDetect::getInstance();
  83.  
  84.  
  85. //$host= gethostname(); $serv_ip = gethostbyname($host);
  86.  
  87. //$is_tor = $tor_detector->check($ip, 80, $serv_ip);
  88.  
  89.  
  90.  
  91.  
  92.  
  93. //echo "tor check start ";
  94. $is_tor = $instance->isTorActive();
  95.  
  96.  
  97. //echo "tor check end ";
  98.  
  99. try{
  100.  
  101. $reader = new Reader('GeoIP2-City.mmdb');
  102.  
  103. $record = $reader->city($ip);
  104. $country = $record->country->name;
  105. $cc  =   $record->country->isoCode;
  106. //add to db info
  107.  
  108. }
  109. catch (GeoIp2\Exception\AddressNotFoundException $e ){
  110. $country = "Not found";
  111. $cc = "NotF";
  112. }
  113.  
  114.  
  115.  $t = $pdo->prepare('select * from `traffic_task` where offer_id = :offer_id and enabled = true limit 1');
  116.             $t->bindParam(':offer_id', $offer_id);
  117.             $t->execute();
  118.  
  119. if ($t->rowCount() > 0)
  120. {
  121.     $res = $t->fetchAll();
  122.     $timestamp = date("Y-m-d H:i:s");
  123. $q =  $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`) values (:ip, :country, :task_id)');
  124.             $q->bindParam(':ip', $ip);
  125.             $q->bindParam(':task_id', $res[0]['id']);
  126.             $q->bindParam(':country', $country);
  127.            
  128.             $q->execute();
  129.            
  130.             echo file_get_contents("usa.txt");
  131. }
  132.            
  133.    
  134.  
  135.  
  136.  
  137. function getIP()
  138. {
  139.     if (isset($_SERVER["HTTP_X_REAL_IP"]))
  140.         return $_SERVER["HTTP_X_REAL_IP"];
  141.     else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
  142.         return $_SERVER ["HTTP_X_FORWARDED_FOR"];
  143.     return $_SERVER['REMOTE_ADDR'];
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement