<?php

use CodeIgniter\Boot;
use Config\Paths;

$minPhpVersion = '8.5';
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
    header('HTTP/1.1 503 Service Unavailable.', true, 503);
    echo sprintf('Your PHP version must be %s or higher to run CodeIgniter. Current version: %s', $minPhpVersion, PHP_VERSION);
    exit(1);
}

$host = $_SERVER['HTTP_HOST'] ?? '';
if ($host === '192.168.30.184' || $host === '192.168.30.106') {
    define('ENVIRONMENT', 'development');
} else {
    define('ENVIRONMENT', 'production');
    if (strncmp($host, 'www.', 4) === 0) {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: http://' . str_ireplace('www.', '', $host) . ($_SERVER['REQUEST_URI'] ?? '/'));
        exit;
    }
}

define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
    chdir(FCPATH);
}

require FCPATH . 'app/Config/Paths.php';

$paths = new Paths();

require $paths->systemDirectory . '/Boot.php';

exit(Boot::bootWeb($paths));
