From ec725fd6894ba5ef06e486ce5dc2815c03192840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Tue, 16 Jan 2024 19:39:54 +0100 Subject: [PATCH] test --- index.php | 26 -------------------------- lib/routing.php | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/index.php b/index.php index 0273e43..2e07b5a 100644 --- a/index.php +++ b/index.php @@ -3,32 +3,6 @@ require "secrets/config.php"; require "lib/navpages.php"; require "lib/routing.php"; -$default_page = "domov"; - -$default_site = "home"; - -$template_dir = "templates/"; - -$static_page_dir = "pages/"; - -$dynamic_page_dir = "dynamic/"; - -$subdomain = basename(explode('.', $_SERVER['HTTP_HOST'])[0]); -$domain = basename(explode('.', $_SERVER['HTTP_HOST'])[1]); -$tld = basename(explode('.', $_SERVER['HTTP_HOST'])[2]); -$page_name = basename($_SERVER["QUERY_STRING"]); -$protocol = getProtocol(); - -if (empty($tld)){ - header("Location: $protocol$default_site.$subdomain.$domain/$default_page"); - return; -} - -if (empty($page_name)){ - header("Location: $protocol$subdomain.$domain.$tld/$default_page"); - return; -} - session_set_cookie_params(0, '/', ".$domain.$tld", true, true); session_start(); diff --git a/lib/routing.php b/lib/routing.php index bcf7587..54b410b 100644 --- a/lib/routing.php +++ b/lib/routing.php @@ -9,6 +9,31 @@ function getProtocol(){ } function getPage($routerConfig){ + $default_page = "domov"; + + $default_site = "home"; + + $template_dir = "templates/"; + + $static_page_dir = "pages/"; + + $dynamic_page_dir = "dynamic/"; + + $subdomain = basename(explode('.', $_SERVER['HTTP_HOST'])[0]); + $domain = basename(explode('.', $_SERVER['HTTP_HOST'])[1]); + $tld = basename(explode('.', $_SERVER['HTTP_HOST'])[2]); + $page_name = basename($_SERVER["QUERY_STRING"]); + $protocol = getProtocol(); + + if (empty($tld)){ + header("Location: $protocol$default_site.$subdomain.$domain/$default_page"); + return; + } + + if (empty($page_name)){ + header("Location: $protocol$subdomain.$domain.$tld/$default_page"); + return; + } $page_dir = "pages/"; $dynamic_page_file = $page_dir . $subdomain . "/" . $page_name . ".php";