page: redirect location option in abort()
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 27 Dec 2020 18:44:33 +0000 (19:44 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 30 Dec 2020 23:22:16 +0000 (00:22 +0100)
error.inc.php
login/index.php
login/pass/index.php
login/post/index.php
page.php

index faa71905a3dc3d7061570f963d6b6ce0b9bac91a..a9669c4fc85d60152e4768fd107aac403b0f1c8d 100644 (file)
@@ -1,9 +1,16 @@
 <?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;
 }
index 0f428ca48f95e8d70bda44ccb11eb31b4013e4a3..8e36628be24128aae6c4664555581390c443694d 100644 (file)
@@ -59,9 +59,7 @@ if (!$User or !$User->login) {
 
 if (isset($_REQUEST['goto'])) {
        $target = ltrim($_REQUEST['goto'], '/');
-       header("Location: /$target");
-       http_response_code(302);
-       exit;
+       abort("/$target", 302);
 }
 
 if (isset($Page->raw)) {
index cd6518662616018bbc7cdbaec8c6d9a8f7167e96..4fb50d0f2993195f9bafc117287d4729dcae1f97 100644 (file)
@@ -14,10 +14,8 @@ if (isset($_GET['token'])) {
        }
 }
 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) {
index 442efefd3e2afa8e62486407108b21817c7bf352..23c445146e95820b5b2612967eecf459303c2f63 100644 (file)
@@ -2,10 +2,8 @@
 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 {
index 35a810ac2a9c6702dd2f9900ff3f1ab844dc9eec..a9607c0cf9ab49d60d7dc78aaca2cba629cedbc3 100644 (file)
--- a/page.php
+++ b/page.php
@@ -16,9 +16,7 @@ $staticpage = "$request.html";
 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")) {
@@ -35,10 +33,8 @@ include_once 'auth.inc.php'; // sets global $User
 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');
        }
 }