Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1); // reports all errors
- ini_set("display_errors", "1"); // shows all errors
- ini_set("log_errors", 1);
- //echo "script start ";
- require 'vendor/autoload.php';
- require_once 'TorDetect.php';
- use GeoIp2\Database\Reader;
- $offer_id = 4;
- $url = "";
- $host = '185.203.118.216';
- $db = 'bptest';
- $user = 'root';
- $pass = 'EdQe4ud06H';
- $charset = 'utf8';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $pdo = new PDO($dsn, $user, $pass, $opt);
- $ip = getIP();
- if (strpos($ip, ',') !== false) {
- $ip_arr = explode(",", $ip);
- $ip = $ip_arr[0];
- }
- $a = $pdo->prepare('select * from ip_blacklist where ip = :ip limit 1');
- $a->bindParam(':ip', $ip);
- $a->execute();
- if ($a->rowCount() > 0)
- {
- //count++
- header('Location: http://yandex.com/');
- exit;
- }
- $b = $pdo->prepare('select * from `hits` where ip = :ip limit 1');
- $b->bindParam(':ip', $ip);
- $b->execute();
- if ($b->rowCount() > 0)
- {
- $date = date("Y-m-d H:i:s");
- $s = $pdo->prepare('insert into ip_blacklist (ip, hit_count) values (:ip, 0)');
- $s->bindParam(':ip', $ip);
- $s->execute();
- header('Location: http://yandex.com/');
- exit;
- }
- $instance = \TorDetect\TorDetect::getInstance();
- //$host= gethostname(); $serv_ip = gethostbyname($host);
- //$is_tor = $tor_detector->check($ip, 80, $serv_ip);
- //echo "tor check start ";
- $is_tor = $instance->isTorActive();
- //echo "tor check end ";
- try{
- $reader = new Reader('GeoIP2-City.mmdb');
- $record = $reader->city($ip);
- $country = $record->country->name;
- $cc = $record->country->isoCode;
- //add to db info
- }
- catch (GeoIp2\Exception\AddressNotFoundException $e ){
- $country = "Not found";
- $cc = "NotF";
- }
- $t = $pdo->prepare('select * from `traffic_task` where offer_id = :offer_id and enabled = true limit 1');
- $t->bindParam(':offer_id', $offer_id);
- $t->execute();
- if ($t->rowCount() > 0)
- {
- $res = $t->fetchAll();
- $timestamp = date("Y-m-d H:i:s");
- $q = $pdo->prepare('insert into `hits` (`ip`, `country`, `task_id`) values (:ip, :country, :task_id)');
- $q->bindParam(':ip', $ip);
- $q->bindParam(':task_id', $res[0]['id']);
- $q->bindParam(':country', $country);
- $q->execute();
- echo file_get_contents("usa.txt");
- }
- function getIP()
- {
- if (isset($_SERVER["HTTP_X_REAL_IP"]))
- return $_SERVER["HTTP_X_REAL_IP"];
- else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
- return $_SERVER ["HTTP_X_FORWARDED_FOR"];
- return $_SERVER['REMOTE_ADDR'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement