diff --git a/index.php b/index.php index 3a03525..2c4bfce 100644 --- a/index.php +++ b/index.php @@ -6,6 +6,7 @@ require_once "lib/navigation.php"; require_once "lib/router.php"; require_once "lib/page.php"; require_once "lib/endpoint.php"; +require_once "lib/account.php"; $routerConfig = array(); $routerRequest = array(); @@ -15,6 +16,11 @@ if(initRouter()) { /** @noinspection PhpArrayIsAlwaysEmptyInspection */ session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true); session_start(); + + if(!isLoggedIn()){ + setDefaultSessionData(); + } + if($routerRequest["type"] == "api") { echo getEndpoint($routerRequest["page_name"]); diff --git a/lib/account.php b/lib/account.php index 074d67e..6eeea8e 100644 --- a/lib/account.php +++ b/lib/account.php @@ -8,6 +8,17 @@ function isLoggedIn(): bool return $_SESSION["ID"] > 0 && !empty($_SESSION["email"]) && $_SESSION["privilegelevel"] >= $routerConfig["logged_in_default_permission_level"]; } +function setDefaultSessionData(): void +{ + $_SESSION["ID"] = 0; + $_SESSION["first_name"] = ""; + $_SESSION["last_name"] = ""; + $_SESSION["nickname"] = ""; + $_SESSION["email"] = ""; + $_SESSION["mcnick"] = ""; + $_SESSION["privilegelevel"] = 0; +} + function generateActivationToken(): string { try { diff --git a/lib/page.php b/lib/page.php index 57a682e..9bbc62b 100644 --- a/lib/page.php +++ b/lib/page.php @@ -73,7 +73,10 @@ function getPage($page_name = null): array|false|string $page = $pageMetadata["output"]; } else{ - $page = file_get_contents($routerConfig["template_dir"] . "404.html"); + $page_tmp = file_get_contents($routerConfig["template_dir"] . "404.html"); + $pageMetadata = parsePageTag($page_tmp); + $page = $pageMetadata["output"]; + http_response_code(404); } print_r($pageMetadata["parameters"]); @@ -96,11 +99,15 @@ function getPage($page_name = null): array|false|string if($page_required_permission < $_SESSION["privilegelevel"]){ if($is_secret_page == 1) { - $page = file_get_contents($routerConfig["template_dir"] . "404.html"); //fake 404 error + $page_tmp = file_get_contents($routerConfig["template_dir"] . "404.html"); + $pageMetadata = parsePageTag($page_tmp); + $page = $pageMetadata["output"]; http_response_code(404); } else{ - $page = file_get_contents($routerConfig["template_dir"] . "403.html"); //deny access if doesnt have permissions + $page_tmp = file_get_contents($routerConfig["template_dir"] . "403.html"); + $pageMetadata = parsePageTag($page_tmp); + $page = $pageMetadata["output"]; http_response_code(403); } }