<?php

  header('Access-Control-Allow-Origin: *');
  $testagent = isset($_GET['a']) ? $_GET['a'] : '#404?$';
  $json = isset($_GET['j']) ? $_GET['j'] : '0';
  $sleep = isset($_GET['s']) ? $_GET['s'] : '0';


  if ($json == '1') {
    header('Content-Type: application/json');
  }

  if ($testagent == "#404?$") {
    $testagent = $_SERVER['HTTP_USER_AGENT'];
  }

  if (ellenorzes($testagent)) {
    if ($json == '1') {
      echo json_encode(["status" => "no", "agent" => htmlspecialchars($testagent)]);
    } else {
      echo "no";
    }
  } else {
    if ($json == '1') {
      echo json_encode(["status" => "ok", "agent" => htmlspecialchars($testagent)]);
    } else {
      echo "ok";
    }
  }

  function ellenorzes($string) {
    if ($string == null || $string == "") {
      return true;
    }
    $botslist = file_get_contents('user-agents_bot-crawler.txt');
    $botarray = explode("\n", $botslist);

    for ($i=0; $i < count($botarray); $i++) {
      if (strpos($botarray[$i], $string) !== false) {
        return true;
      }
    }

    return false;
  }


sleep($sleep);
?>
