From b7d7c4498e3d809c44dc4f539f81241e97f2094f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 29 Mar 2025 10:34:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Make=20the=20router=20handle=20r?= =?UTF-8?q?edirect=20and=20harden=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/renderer.php | 5 ----- kernel/router.php | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kernel/renderer.php b/kernel/renderer.php index 2166e66..e5d97bd 100644 --- a/kernel/renderer.php +++ b/kernel/renderer.php @@ -50,11 +50,6 @@ class Renderer { die(); } - public function redirect($redirection) { - header("Location: " . $redirection); - die(); - } - public function simple($title, $content) { $this->prepare("title", $title); $this->prepare("content", $content); diff --git a/kernel/router.php b/kernel/router.php index e3380af..ab31917 100644 --- a/kernel/router.php +++ b/kernel/router.php @@ -11,6 +11,7 @@ class Router { public $controller; public $func; public $characterId = -1; + public $uri; private $namespaces = []; @@ -45,12 +46,23 @@ class Router { } } + public function redirect($redirection) { + if ($this->uri == null) { + $this->parseUrl(); + } + if ($this->uri != $redirection) { + header("Location: " . $redirection); + die(); + } + } + private function getFromUrl($requestParts, $index, $default) { return (isset($requestParts[$index]) && $requestParts[$index] != null) ? $requestParts[$index] : $default; } private function parseUrl() { global $renderer; + $this->uri = $_SERVER['REQUEST_URI']; $requestUri = trim($_SERVER['REQUEST_URI'], '/'); $requestParts = explode('/', $requestUri);