diff --git a/auth/auth.php b/auth/auth.php index 3015ec3..be15fb1 100644 --- a/auth/auth.php +++ b/auth/auth.php @@ -42,9 +42,23 @@ function dreamgirl_check_credentials(string $username, string $password): bool { return hash_equals($expectedSha256, $gotSha256); } +function dreamgirl_base_path(): string { + // If deployed under /dreamgirl, SCRIPT_NAME is like /dreamgirl/index.php + // If at web root, SCRIPT_NAME is like /index.php + $script = isset($_SERVER['SCRIPT_NAME']) ? (string)$_SERVER['SCRIPT_NAME'] : ''; + $dir = rtrim(str_replace('\\', '/', dirname($script)), '/'); + return ($dir === '' || $dir === '.') ? '' : $dir; +} + +function dreamgirl_url(string $path): string { + $base = dreamgirl_base_path(); + $p = ltrim($path, '/'); + return $base . '/' . $p; +} + function dreamgirl_require_login_page(): void { if (dreamgirl_is_logged_in()) return; - header('Location: /login.php'); + header('Location: ' . dreamgirl_url('login.php')); exit; } diff --git a/index.html b/index.html index 29c12a3..102e7ba 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,13 @@ - + Redirecting... - Continue + Continue diff --git a/index.php b/index.php index c5d968c..35ee73c 100644 --- a/index.php +++ b/index.php @@ -35,7 +35,7 @@ dreamgirl_require_login_page();

NCue

-
Logout
+
Logout