Add 404 handling

Fixes #5.
This commit is contained in:
Florine W. Dekker 2021-03-19 20:59:53 +01:00
parent c598fb603e
commit b3423a7450
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 34 additions and 11 deletions

View File

@ -1,4 +1,6 @@
<?php
include("render.php");
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
@ -20,4 +22,19 @@ if ($result) {
}
include("index.html");
$body = "";
if ($path != "/") {
$body =
"<b>Link not found</b><br /><br />
The short URL https://fwdkr.co{$path} could not be found.<br /><br />
<br /><br />";
}
$body .=
"<b>About fwdkr.co</b><br /><br />
You've arrived at this page because you typed or linked to \"fwdkr.co\", the URL shortcut for
<a href=\"https://fwdekker.com/\">fwdekker.com</a>.<br /><br />
Whenever you see a \"fwdkr.co\" link, you can trust that it will always take you to a website affiliated with
FWDekker.";
render_page("FWDekker", $body);

View File

@ -1,9 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<?php
/**
* Renders a simply fwdkr.co page.
*
* @param string $title the page's title, as displayed in the tab
* @param string $body the bit of text to display to the user
*/
function render_page(string $title, string $body)
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FWDekker</title>
<title><?= $title ?></title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style>
@ -28,12 +38,8 @@
<body>
<div id="wrapper">
<h1><a href="https://fwdekker.com/">FWDekker</a></h1>
<b>About fwdkr.co</b><br /><br />
You've arrived at this page because you typed or linked to "fwdkr.co", the URL shortcut for
<a href="https://fwdekker.com/">fwdekker.com</a>.<br /><br />
Whenever you see a "fwdkr.co" link, you can trust that it will always take you to a website affiliated with
FWDekker.
<?= $body ?>
</div>
</body>
</html>
</html><?php
}