🐘
header.php
Back
📝 Php ⚡ Executable Ctrl+S: Save • Ctrl+R: Run • Ctrl+F: Find
<?php if (session_status() === PHP_SESSION_NONE) session_start(); // Build a safe redirect back to the current page (path + query), e.g. /component1/index.php?x=1 $current_path = $_SERVER['REQUEST_URI'] ?? '/'; $redirect_qs = urlencode($current_path); // Get page title from global variable or default $page_title = $GLOBALS['page_title'] ?? 'DevBrewing'; ?> <style> .site-header { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); backdrop-filter: blur(20px); border-bottom: 1px solid rgba(71, 85, 105, 0.3); padding: 0.75rem 1rem; position: sticky; top: 0; z-index: 100; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); } .site-header__container { display: flex; justify-content: space-between; align-items: center; max-width: 1200px; margin: 0 auto; gap: 1rem; } .site-header__logo { color: #f8fafc; text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: -0.025em; background: linear-gradient(135deg, #60a5fa, #3b82f6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; transition: opacity 0.2s ease; } .site-header__logo:hover { opacity: 0.8; } .site-header__auth { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; } .site-header__user { display: flex; align-items: center; gap: 0.75rem; color: #cbd5e1; font-size: 0.875rem; font-weight: 500; } .site-header__username { color: #f1f5f9; font-weight: 600; padding: 0.375rem 0.75rem; background: rgba(30, 41, 59, 0.5); border-radius: 0.5rem; border: 1px solid rgba(71, 85, 105, 0.3); } .site-header__btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.5rem 1rem; border-radius: 0.5rem; text-decoration: none; font-weight: 600; font-size: 0.875rem; transition: all 0.2s ease; border: 1px solid transparent; white-space: nowrap; } .site-header__btn--login { background: linear-gradient(135deg, #6366f1, #4f46e5); color: white; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); } .site-header__btn--login:hover { background: linear-gradient(135deg, #4f46e5, #4338ca); transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); } .site-header__btn--signup { background: linear-gradient(135deg, #10b981, #059669); color: white; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); } .site-header__btn--signup:hover { background: linear-gradient(135deg, #059669, #047857); transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); } .site-header__btn--logout { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); padding: 0.375rem 0.75rem; font-size: 0.8rem; } .site-header__btn--logout:hover { background: linear-gradient(135deg, #dc2626, #b91c1c); transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); } /* Mobile optimizations */ @media (max-width: 640px) { .site-header { padding: 0.75rem; } .site-header__container { gap: 0.5rem; } .site-header__logo { font-size: 1.125rem; } .site-header__auth { gap: 0.5rem; } .site-header__user { flex-direction: column; align-items: flex-end; gap: 0.5rem; font-size: 0.8rem; } .site-header__username { padding: 0.25rem 0.5rem; font-size: 0.8rem; } .site-header__btn { padding: 0.4rem 0.75rem; font-size: 0.8rem; } .site-header__btn--logout { padding: 0.3rem 0.6rem; font-size: 0.75rem; } } @media (max-width: 480px) { .site-header__user span:not(.site-header__username) { display: none; } } </style> <header class="site-header"> <div class="site-header__container"> <a href="<?php echo SITE_URL; ?>" class="site-header__logo"><?php echo htmlspecialchars($page_title); ?></a> <div class="site-header__auth"> <?php if (!empty($_SESSION['username'])): ?> <div class="site-header__user"> <span>Welcome back</span> <span class="site-header__username"><?php echo htmlspecialchars($_SESSION['username']); ?></span> </div> <a href="<?php echo SITE_URL; ?>/core/auth/logout.php" class="site-header__btn site-header__btn--logout">Logout</a> <?php else: ?> <a href="<?php echo SITE_URL; ?>/core/auth/login.php?redirect=<?php echo $redirect_qs; ?>" class="site-header__btn site-header__btn--login"> Login </a> <a href="<?php echo SITE_URL; ?>/core/auth/signup.php?redirect=<?php echo $redirect_qs; ?>" class="site-header__btn site-header__btn--signup"> Sign up </a> <?php endif; ?> </div> </div> </header>