<?php declare(strict_types=1); if (session_status() === PHP_SESSION_NONE) { ini_set('session.cookie_httponly', '1'); $isSecure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['SERVER_PORT'] ?? 0) == 443); ini_set('session.cookie_secure', $isSecure ? '1' : '0'); ini_set('session.cookie_samesite', 'Strict'); ini_set('session.cookie_lifetime', '0'); ini_set('session.use_strict_mode', '1'); ini_set('session.gc_maxlifetime', '3600'); session_start(); } $credPath = dirname(__DIR__, 2) . '/shared/credentials.php'; if (file_exists($credPath)) { require_once $credPath; } if (!defined('STORE_ROOT')) { define('STORE_ROOT', dirname(__DIR__)); } require_once __DIR__ . '/config.php'; require_once __DIR__ . '/db.php'; require_once __DIR__ . '/encrypt.php'; require_once __DIR__ . '/auth.php'; require_once __DIR__ . '/store_secrets.php'; if (file_exists(__DIR__ . '/admin-auth.php')) { require_once __DIR__ . '/admin-auth.php'; } require_once __DIR__ . '/obfuscate.php'; require_once __DIR__ . '/telemetry.php'; require_once __DIR__ . '/App.php'; require_once __DIR__ . '/security.php';  require_once __DIR__ . '/payment_bridge.php'; require_once __DIR__ . '/email_bridge.php'; if (!defined('STORE_ROOT')) { define('STORE_ROOT', dirname(__DIR__)); } $store_id = 1; $store_name = ''; $store_tagline = ''; $accent_color = '#2D6A4F'; $labels = []; try { $defaultNameRow = Database::one("SELECT setting_value FROM settings WHERE setting_key = 'default_store_name'"); $store_name = $defaultNameRow ? Crypt::d($defaultNameRow['setting_value']) : ''; $defaultTagRow = Database::one("SELECT setting_value FROM settings WHERE setting_key = 'default_store_tagline'"); $store_tagline = $defaultTagRow ? Crypt::d($defaultTagRow['setting_value']) : ''; } catch (\Throwable $e) {} try { $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $host = explode(':', $host)[0]; $store = Database::one( "SELECT id, store_name, nickname, accent_color, tagline, is_active, maintenance_mode FROM stores WHERE domain = :d LIMIT 1", [':d' => $host] ); if ($store) { $store_id = (int)$store['id']; $resolved = Crypt::render($store['store_name']); if ($resolved) { $store_name = $resolved; } elseif (!empty($store['store_name'])) { $store_name = $store['store_name']; } elseif (!empty($store['nickname'])) { $store_name = $store['nickname']; } $resolvedTag = isset($store['tagline']) ? Crypt::render($store['tagline']) : ''; if ($resolvedTag) { $store_tagline = $resolvedTag; } elseif (!empty($store['tagline'])) { $store_tagline = $store['tagline']; } $accent_color = $store['accent_color'] ?: '#2D6A4F'; if (!$store['is_active']) { http_response_code(503); exit; } if ($store['maintenance_mode']) { http_response_code(503); exit; } } } catch (\Throwable $e) {} if (!$store_name) $store_name = 'Store'; try { $labelRows = Database::all("SELECT label_key, label_value FROM ui_labels WHERE store_id = :sid OR store_id IS NULL ORDER BY store_id ASC", [':sid' => $store_id]); foreach ($labelRows as $lr) { $labels[$lr['label_key']] = Crypt::d($lr['label_value']) ?: $lr['label_value']; } } catch (\Throwable $e) {} $L = function(string $key, string $fallback = '') use (&$labels): string { return htmlspecialchars($labels[$key] ?? $fallback, ENT_QUOTES, 'UTF-8'); }; $Lr = function(string $key, string $fallback = '') use (&$labels): string { return $labels[$key] ?? $fallback; }; $csrf_token = Auth::csrf(); $clientIp = $_SERVER['REMOTE_ADDR'] ?? ''; if ($clientIp) { try { $blocked = Database::one( "SELECT id FROM blacklist WHERE ip_address = :ip AND (expires_at IS NULL OR expires_at > NOW())", [':ip' => $clientIp] ); if ($blocked) { http_response_code(403); die("Access Denied"); } } catch (\Throwable $e) { error_log("[Init] Blacklist check failed: " . $e->getMessage()); } }