<?php
# custom error handling for MinimEdit
-function abort($body, $status = NULL)
+function abort($body, string $status = NULL)
{
- if ($status) header("HTTP/1.1 $status");
+ if ($status) {
+ header("HTTP/1.1 $status");
+ if ($status[0] === '3') {
+ # redirection (body specifies target)
+ header("Location: $body");
+ exit;
+ }
+ }
print "$body\n";
exit;
}
if (isset($_REQUEST['goto'])) {
$target = ltrim($_REQUEST['goto'], '/');
- header("Location: /$target");
- http_response_code(302);
- exit;
+ abort("/$target", 302);
}
if (isset($Page->raw)) {
}
}
elseif (!$User->login) {
- http_response_code(303);
$target = urlencode($_SERVER['REQUEST_URI']);
- header("Location: /login?goto=$target");
- exit;
+ abort("/login?goto=$target", 303);
}
if ($_POST) {
if (!$User) return;
if (!$User->login) {
- http_response_code(303);
$target = urlencode($_SERVER['REQUEST_URI']);
- header("Location: /login?goto=$target");
- exit;
+ abort("/login?goto=$target", 303);
}
elseif ($User->admin('user') and $username = @$_REQUEST['login']) {
try {
if (file_exists($staticpage)) {
if (is_link($staticpage)) {
$target = preg_replace('/\.html$/', '', readlink($staticpage));
- header("HTTP/1.1 302 Shorthand");
- header("Location: $target");
- exit;
+ abort($target, '302 Shorthand');
}
}
elseif (file_exists("$request/index.html")) {
if ($Page->restricted) {
# access restriction
if (!$User->login) {
- http_response_code(303);
$target = urlencode($Page->link);
- header("Location: /login?goto=$target");
- exit;
+ abort("/login?goto=$target", '303 Eerst inloggen');
}
}