id/index.php

87 lines
2 KiB
PHP
Raw Normal View History

2023-10-31 18:43:21 +00:00
<?php
session_start();
2023-10-31 20:21:33 +00:00
include("config.php");
2023-11-06 16:38:18 +00:00
include("id_handler.php");
include("time_handler.php");
function does_variable_exists( $variable ) {
return (isset($$variable)) ? "true" : "false";
}
2023-10-31 20:21:33 +00:00
2023-10-31 18:43:21 +00:00
$host_string = $_SERVER['HTTP_HOST'];
$host = explode('.', $host_string);
$uri_string = $_SERVER['REQUEST_URI'];
$query_string = explode('?', $uri_string);
2023-10-31 20:21:33 +00:00
$path = $query_string[0];
2023-11-06 16:38:18 +00:00
if (str_ends_with($path,'/') && $path != "/") {
header('Location: '.substr($path,0, -1));
exit;
}
2023-10-31 18:43:21 +00:00
$uri = array_values(array_filter(explode('/', $uri_string)));
if(isset($query_string[1])) {
2023-10-31 20:21:33 +00:00
$uri_string = $query_string[0];
$query_string = explode('&', $query_string[1]);
$query = array();
foreach($query_string as $string) {
2023-10-31 18:43:21 +00:00
$bits = explode('=', $string);
$query[$bits[0]] = $bits[1];
2023-10-31 20:21:33 +00:00
}
2023-10-31 18:43:21 +00:00
}
else {
2023-11-06 16:38:18 +00:00
$query = array();
2023-10-31 18:43:21 +00:00
}
2023-11-06 16:38:18 +00:00
$pdo = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD, PDO_OPTIONS);
2023-10-31 20:21:33 +00:00
2023-11-06 16:38:18 +00:00
$include = "404.html";
2023-10-31 20:21:33 +00:00
// routing
2023-11-06 16:38:18 +00:00
$paths = array(
"/" => ["landing.php"],
"/admin/init/database" => ["admin_initdatabase.php"],
"/admin/accounts" => ["admin_accounts.php"],
"/account" => ["account.php", "Your account"],
"/signin" => ["signin.php", "Sign in"],
"/signup" => ["signup.php", "Sign up"],
"/signout" => ["signout.php", "Signed out"],
"/forgot_password" => ["forgot_password.php", "Forgot password"],
"/admin/signinas" => ["signinas.php"]
);
if (isset($paths[$path])) {
$include = $paths[$path][0];
if (isset($paths[$path][1])) {
$doc_title = $paths[$path][1];
}
2023-10-31 20:21:33 +00:00
}
2023-11-06 16:38:18 +00:00
2023-10-31 20:21:33 +00:00
else {
$doc_title = "404";
http_response_code(404);
}
2023-10-31 18:43:21 +00:00
?>
<!DOCTYPE html>
<html lang="en">
<head>
2023-10-31 20:21:33 +00:00
<?php include("head.php"); ?>
2023-10-31 18:43:21 +00:00
</head>
<body>
<?php include("header.php"); ?>
<main>
2023-11-06 16:38:18 +00:00
<?php
if ($uri[0] == "admin" && $_SESSION['id'] != "281G3NV") {
http_response_code(401);
die("<img src='https://http.cat/401.jpg'>");
}
include($include); ?>
2023-10-31 18:43:21 +00:00
</main>
<?php include("footer.php"); ?>
</body>
</html>