diff --git a/.hta_404 copy.php b/.hta_404 copy.php new file mode 100644 index 0000000..b5e9ee8 --- /dev/null +++ b/.hta_404 copy.php @@ -0,0 +1,77 @@ +prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); + $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_ASSOC); +} + +function saveToCache($filePath, $content) { + if (!file_put_contents($filePath, $content)) { + error_log("Failed to write cache file: $filePath"); + } +} + + + +if (empty($slug)) { + // echo "Slug not provided!"; + // exit; +} + +$fileName = $slug . ".html"; +$filePath = __DIR__ . '/notice/' . $fileName; + +ob_start(); + +$shouldCache = false; // Flag to determine if content should be cached. + +if (!serveStaticFile($filePath)) { + try { + $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $content = fetchFromDatabase($slug, $pdo); + if ($content && isset($content['content']) && $content['content']) { + echo '
' . htmlspecialchars($content['title']) . '
+Page not found (404).
+ Back to home +Error: " . htmlspecialchars($e->getMessage()) . "
"; + } +} + +$htmlContent = ob_get_clean(); + +// Save to cache only if content was found. +if ($shouldCache) { + saveToCache($filePath, $htmlContent); +} + +echo $htmlContent; +?> \ No newline at end of file diff --git a/.hta_404.php b/.hta_404.php index 9f9ebf2..7cb22b9 100644 --- a/.hta_404.php +++ b/.hta_404.php @@ -1,76 +1,56 @@ prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); - $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); - $stmt->execute(); - return $stmt->fetch(PDO::FETCH_ASSOC); -} + // echo $querySlug; -function saveToCache($filePath, $content) { - if (!file_put_contents($filePath, $content)) { - error_log("Failed to write cache file: $filePath"); - } -} - - - -if (empty($slug)) { - // echo "Slug not provided!"; - // exit; -} - -$fileName = $slug . ".html"; -$filePath = __DIR__ . '/notice/' . $fileName; - -ob_start(); - -$shouldCache = false; // Flag to determine if content should be cached. - -if (!serveStaticFile($filePath)) { try { - $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $content = fetchFromDatabase($slug, $pdo); - if ($content && isset($content['content']) && $content['content']) { - echo '' . htmlspecialchars($content['title']) . '
-Page not found (404).
- Back to home -'.$content[0]['title'].'
Page not found (404).
+ Back to home +Error: " . htmlspecialchars($e->getMessage()) . "
"; + $in_page_message = "Error: " . $e->getMessage() . "
"; } -} -$htmlContent = ob_get_clean(); + // Render page content here + echo $pageContent; -// Save to cache only if content was found. -if ($shouldCache) { - saveToCache($filePath, $htmlContent); -} + $footerContent = file_get_contents('./.hta_footer.php'); + + // if($fileExtension[1] && $fileExtension[1] === 'html'){ + // $filePath = __DIR__ . '/notice/' . $fileName; + // } else{ + // $filePath = __DIR__ . '/notice/' . $fileName . '.html'; + // } + $filePath = __DIR__ . '/notice/' . $fileName; + $totalPageContent = $headerContent . $pageContent . $footerContent; + + file_put_contents($filePath, $totalPageContent); -echo $htmlContent; ?> \ No newline at end of file diff --git a/.hta_config/env.php b/.hta_config/env.php index 99ab86f..5c45e9f 100644 --- a/.hta_config/env.php +++ b/.hta_config/env.php @@ -1,6 +1,6 @@