From ffcb263131a49c10689422ac09485f48824d29fd Mon Sep 17 00:00:00 2001 From: dsyoon Date: Sun, 8 Feb 2026 12:39:03 +0900 Subject: [PATCH] Fix auth redirects for /dreamgirl subpath Make login/logout and redirects work when deployed under a subdirectory (e.g. /dreamgirl). Co-authored-by: Cursor --- auth/auth.php | 16 +++++++++++++++- index.html | 6 +++--- index.php | 2 +- login.php | 4 ++-- logout.php | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) 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