Files
edu/skin/_tmp_session_check.php
T

89 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
// Temporary session diagnostics page.
// Remove this file after verification.
$accessKey = 'baroncs-session-check-20260408';
$key = (string)($_GET['key'] ?? '');
if ($key !== $accessKey) {
http_response_code(403);
header('Content-Type: text/plain; charset=UTF-8');
echo "Forbidden";
exit;
}
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$now = time();
$firstSeen = isset($_SESSION['diag_first_seen']) ? (int)$_SESSION['diag_first_seen'] : $now;
$lastSeenBefore = isset($_SESSION['diag_last_seen']) ? (int)$_SESSION['diag_last_seen'] : null;
$_SESSION['diag_first_seen'] = $firstSeen;
$_SESSION['diag_last_seen'] = $now;
$_SESSION['diag_hit_count'] = (int)($_SESSION['diag_hit_count'] ?? 0) + 1;
$cookieParams = session_get_cookie_params();
$phpSessCookie = $_COOKIE[session_name()] ?? '';
header('Content-Type: text/html; charset=UTF-8');
?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Session Diagnostics</title>
<style>
body { font-family: Arial, sans-serif; margin: 24px; line-height: 1.5; }
h1 { margin: 0 0 12px; }
.box { border: 1px solid #ddd; border-radius: 8px; padding: 14px; margin: 12px 0; }
.k { color: #666; display: inline-block; min-width: 240px; }
.v { font-weight: 600; }
.warn { color: #b54708; }
.ok { color: #027a48; }
</style>
</head>
<body>
<h1>Temporary Session Diagnostics</h1>
<p class="warn">Check complete, then delete this file immediately.</p>
<div class="box">
<div><span class="k">Server time</span><span class="v"><?php echo date('Y-m-d H:i:s T', $now); ?></span></div>
<div><span class="k">PHP version</span><span class="v"><?php echo PHP_VERSION; ?></span></div>
<div><span class="k">Session name</span><span class="v"><?php echo htmlspecialchars(session_name(), ENT_QUOTES, 'UTF-8'); ?></span></div>
<div><span class="k">Session ID</span><span class="v"><?php echo htmlspecialchars(session_id(), ENT_QUOTES, 'UTF-8'); ?></span></div>
<div><span class="k">Session save path</span><span class="v"><?php echo htmlspecialchars((string)ini_get('session.save_path'), ENT_QUOTES, 'UTF-8'); ?></span></div>
</div>
<div class="box">
<div><span class="k">ini: session.cookie_lifetime</span><span class="v"><?php echo (string)ini_get('session.cookie_lifetime'); ?></span></div>
<div><span class="k">ini: session.gc_maxlifetime</span><span class="v"><?php echo (string)ini_get('session.gc_maxlifetime'); ?></span></div>
<div><span class="k">cookie params lifetime</span><span class="v"><?php echo (string)$cookieParams['lifetime']; ?></span></div>
<div><span class="k">cookie params path</span><span class="v"><?php echo htmlspecialchars((string)$cookieParams['path'], ENT_QUOTES, 'UTF-8'); ?></span></div>
<div><span class="k">cookie params domain</span><span class="v"><?php echo htmlspecialchars((string)$cookieParams['domain'], ENT_QUOTES, 'UTF-8'); ?></span></div>
<div><span class="k">cookie params secure</span><span class="v"><?php echo $cookieParams['secure'] ? 'true' : 'false'; ?></span></div>
<div><span class="k">cookie params httponly</span><span class="v"><?php echo $cookieParams['httponly'] ? 'true' : 'false'; ?></span></div>
<div><span class="k">cookie value present</span><span class="v"><?php echo $phpSessCookie !== '' ? 'yes' : 'no'; ?></span></div>
</div>
<div class="box">
<div><span class="k">First seen</span><span class="v"><?php echo date('Y-m-d H:i:s T', $firstSeen); ?></span></div>
<div><span class="k">Last seen before this request</span><span class="v"><?php echo $lastSeenBefore ? date('Y-m-d H:i:s T', $lastSeenBefore) : 'none'; ?></span></div>
<div><span class="k">Hit count in same session</span><span class="v"><?php echo (string)$_SESSION['diag_hit_count']; ?></span></div>
<div><span class="k">Idle seconds since previous hit</span><span class="v"><?php echo $lastSeenBefore ? (string)max(0, $now - $lastSeenBefore) : '0'; ?></span></div>
</div>
<div class="box">
<p><strong>How to test quickly</strong></p>
<ol>
<li>Refresh this page and verify Hit count increases.</li>
<li>Close browser completely, reopen, access this page again, compare Session ID.</li>
<li>Leave idle for 20-40 minutes, revisit and see if Session ID/Hit count resets.</li>
</ol>
<p class="ok">If Session ID changes or Hit count resets, session expired or cookie was dropped.</p>
</div>
</body>
</html>