<?php
declare(strict_types=1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once $_SERVER['DOCUMENT_ROOT'] . '/sys/sys.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/sys/db.php';

$query = "SELECT `black_links` FROM `sett` LIMIT 1";
$result = $mysqli->query($query);
if ($result) {
    $set = $result->fetch_assoc();
} else {
    die('Ошибка при получении настроек: ' . $mysqli->error);
}

$b = 400;
if (!empty($_POST['key'])) {
    $haystack = json_decode($set['black_links']);

    $pos = check_url($_POST['key'], $haystack);
    if ($pos === false) {
        $b = 200;
    }
}

header('Content-Type: application/json');
echo json_encode($b);
die;