summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/class/globals.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/class/globals.php b/app/class/globals.php
index 3512961..c936488 100644
--- a/app/class/globals.php
+++ b/app/class/globals.php
@@ -19,4 +19,38 @@
define("__VERSION__", "v0.0");
+/*
+ * Get the application root path. This is an absolute path on the server.
+ */
+function ar() : string
+{
+ return substr($_SERVER['SCRIPT_NAME'], 0, -10); // 10 = strlen of "/index.php"
+}
+
+/*
+ * Get the current page's path. This is an absolute path on the server.
+ */
+function ap() : string
+{
+ return ar() . $_SERVER['PATH_INFO'];
+}
+
+/*
+ * Redirect to the given URL and die.
+ */
+function redirect(string $url) : void
+{
+ header("Location: " . $url);
+ exit;
+}
+
+/*
+ * Redirect to the given in-app URL and die. The given URL should be a path
+ * relative to the app root.
+ */
+function location(string $path) : void
+{
+ redirect(ar() . $path);
+}
+
?>