리펙토링 #6 참고

This commit is contained in:
Lectom C Han
2026-02-05 12:38:34 +09:00
parent 46b30af839
commit 7034a3643a
17 changed files with 76 additions and 369 deletions

View File

@@ -57,3 +57,25 @@ function kngil_load_env_once(string $path): void
$_SERVER[$name] = $value;
}
}
// 세션 쿠키 경로를 루트로 고정해 경로 변경 시 로그인 상태가 유지되도록 합니다.
function kngil_start_session(): void
{
if (session_status() !== PHP_SESSION_NONE) {
return;
}
$params = session_get_cookie_params();
$samesite = $params['samesite'] ?? 'Lax';
session_set_cookie_params([
'lifetime' => $params['lifetime'],
'path' => '/',
'domain' => $params['domain'],
'secure' => $params['secure'],
'httponly' => $params['httponly'],
'samesite' => $samesite,
]);
session_start();
}

View File

@@ -1,5 +1,6 @@
<?php
session_start();
require_once __DIR__ . '/env.php';
kngil_start_session();
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
$input = json_decode(file_get_contents('php://input'), true);

View File

@@ -5,7 +5,8 @@
* - secret_key: MY_SECRET_KEY
*/
session_start();
require_once __DIR__ . '/env.php';
kngil_start_session();
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
header('Content-Type: application/json; charset=utf-8');
@@ -209,4 +210,4 @@ try {
'error' => true,
'message' => $e->getMessage()
], JSON_UNESCAPED_UNICODE);
}
}

View File

@@ -14,7 +14,7 @@ if (session_status() === PHP_SESSION_NONE) {
if (empty($_SESSION['login'])) {
echo "<script>
alert('로그인 후 이용 가능합니다.');
location.href = '/qa_list.skin';
location.href = '/qa_list';
</script>";
exit;
}
@@ -92,7 +92,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delet
$pdo->commit();
header("Location: /qa_list.skin");
header("Location: /qa_list");
exit;
} catch (Exception $e) {
@@ -230,4 +230,4 @@ $isOwner = ($post['user_id'] === $me);
/* ===============================
12. 스킨 렌더링
=============================== */
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_detail.skin.php';
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_detail.php';

View File

@@ -1,7 +1,7 @@
<?php
/**
* Q&A 리스트 컨트롤러
* - 스킨: /kngil/skin/qa_list.skin.php (URL: /qa_list.skin)
* - 스킨: /kngil/skin/qa_list.php (URL: /qa_list)
*/
ini_set('display_errors', 1);
@@ -149,4 +149,4 @@ $totalPages = (int)ceil($totalCount / $pageSize);
/* =========================
7. 스킨 렌더링
========================= */
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_list.skin.php';
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_list.php';

View File

@@ -42,7 +42,7 @@ try {
]);
// 상세 페이지로 복귀
header("Location: /kngil/bbs/qa_detail.php?id={$postId}");
header("Location: /qa_detail?id={$postId}");
exit;
} catch (Exception $e) {

View File

@@ -17,7 +17,7 @@ if (session_status() === PHP_SESSION_NONE) {
if (empty($_SESSION['login'])) {
echo "<script>
alert('로그인이 필요합니다.');
location.href = '/qa_list.skin';
location.href = '/qa_list';
</script>";
exit;
}
@@ -216,7 +216,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
handle_file_uploads($pdo, $postId);
}
header("Location: /kngil/bbs/qa_detail.php?id={$postId}");
header("Location: /qa_detail?id={$postId}");
exit;
} catch (Exception $e) {
@@ -228,4 +228,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
/* ===============================
7. 화면 출력
=============================== */
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_write.skin.php';
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_write.php';