From 9e4943b4eb4bf238e43cbbf9ae8ac07a90501c02 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Wed, 9 Mar 2022 10:41:12 +0100 Subject: [PATCH] Add redirect script --- redirect.php | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 redirect.php diff --git a/redirect.php b/redirect.php new file mode 100644 index 0000000..7d69983 --- /dev/null +++ b/redirect.php @@ -0,0 +1,79 @@ +connect_errno) { + header("500 Internal Server Error"); + die($SQL['Handle']->connect_errno." ".$SQL['Handle']->connect_error); + } +} + +{ // Prepare a few statements. + $STATEMENTS = array(); + $STATEMENTS["LookUp"] = << $v) { + $STATEMENTS[$k] = $SQL['Handle']->prepare($v); + } +} + +// Redirect the user according to found information +$name = urldecode($_SERVER['REQUEST_URI']); +$STATEMENTS['LookUp']->bind_param('s', $name); +if(!$STATEMENTS['LookUp']->execute()) { + header("Service Unavailable", true, 503); + die($SQL['Handle']->errno." ".$SQL['Handle']->error); +} + +// +$res = $STATEMENTS['LookUp']->get_result(); +if ($res->num_rows == 0) { + // Insert the undiscovered URL into the redirect database. + $STATEMENTS['Insert']->bind_param('s', $name); + if (!$STATEMENTS['Insert']->execute()) { + header("Service Unavailable", true, 503); + die($SQL['Handle']->errno." ".$SQL['Handle']->error); + } else { + if (!$STATEMENTS['Insert']->get_result()) { + header("Service Unavailable", true, 503); + die($SQL['Handle']->errno." ".$SQL['Handle']->error); + } + } + header("Location: https://www.xaymar.com/404.html"); +} else { + while($obj = $res->fetch_object()) { + if ($obj->target != null) { + header("Location: ".$obj->target, true, 307); + } else { + header("Location: https://www.xaymar.com/404.html"); + } + } +} +$res->close(); + +die(); \ No newline at end of file