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;
- $url = "";
- $host = 'localhost';
- $db = 'testtest';
- $user = 'root';
- $pass = 'flsGxvQTxT';
- $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];
- }
- if($ip == "67.137.36.66")
- {exit;}
- $sng_codes = [
- 'RU',
- 'UA',
- 'BY',
- 'KZ'
- ];
- $allowed_codes = [
- 'CA',
- 'US'
- ];
- $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";
- }
- //echo "sng check start ";
- if(in_array($cc, $sng_codes))
- {
- exit;
- }
- if(!in_array($cc, $allowed_codes))
- {
- header('Location: http://yandex.com/');
- exit;
- }
- //echo "sng check end ";
- $date = date('Y-m-d H:i:s');
- $q = $pdo->prepare('insert into `hits` (ip, country, date) values (:ip, :country, :date) ');
- $q->bindParam(':ip', $ip);
- $q->bindParam(':country', $country);
- $q->bindParam(':date', $date);
- $q->execute();
- echo "";
- echo file_get_contents("caa.txt");
- echo $url;
- 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'];
- }
Add Comment
Please, Sign In to add comment