Skip to content

Commit c5e135f

Browse files
committed
redirect uses current page as default value
1 parent a2e3fb3 commit c5e135f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

resources/lib/UnityHTTPD.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public static function die(mixed $x = null, bool $show_user = false): never
3232
}
3333
}
3434

35-
public static function redirect($dest): never
35+
public static function redirect(?string $dest = null): never
3636
{
37+
$dest ??= pathJoin(CONFIG["site"]["prefix"], $_SERVER["REQUEST_URI"]);
3738
header("Location: $dest");
3839
self::errorToUser("Redirect failed, click <a href='$dest'>here</a> to continue.", 302);
3940
self::die();

resources/lib/utils.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,15 @@ function mbDetectEncoding(string $string, ?array $encodings = null, mixed $_ = n
7070
}
7171
return $output;
7272
}
73+
74+
/* https://stackoverflow.com/a/15575293/18696276 */
75+
function pathJoin()
76+
{
77+
$paths = [];
78+
foreach (func_get_args() as $arg) {
79+
if ($arg !== "") {
80+
$paths[] = $arg;
81+
}
82+
}
83+
return preg_replace("#/+#", "/", join("/", $paths));
84+
}

resources/templates/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// header also needs to handle POST data. So this header does the PRG redirect
1717
// for all pages.
1818
unset($_POST); // unset ensures that header must not come before POST handling
19-
UnityHTTPD::redirect(CONFIG["site"]["prefix"] . $_SERVER['REQUEST_URI']);
19+
UnityHTTPD::redirect();
2020
}
2121

2222
if (isset($SSO)) {

0 commit comments

Comments
 (0)