summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-02-13 03:59:41 -0500
committerMalf Furious <m@lfurio.us>2017-02-13 03:59:41 -0500
commit912b28d44b340f9c418f3714d38df40e06f6f6da (patch)
tree19a5c02b2b1bcde58d5e00a9ee92d4ddd7448535 /app
parentf8db4aae02465dabaf7907f5e821414eeeea14bf (diff)
downloadscrott-912b28d44b340f9c418f3714d38df40e06f6f6da.tar.gz
scrott-912b28d44b340f9c418f3714d38df40e06f6f6da.zip
Add app-root(), app-path(), and similar function to globals.php
Diffstat (limited to 'app')
-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);
+}
+
?>