s1
This commit is contained in:
59
faculty/.hta_404.php
Normal file
59
faculty/.hta_404.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
require('.hta_config/env.php');
|
||||
require('./.hta_header.php');
|
||||
|
||||
// echo 'Notice 404+1';
|
||||
|
||||
$headerContent = file_get_contents('./.hta_header.php');
|
||||
$requestUri = $_SERVER['REQUEST_URI'];
|
||||
// echo $requestUri;
|
||||
|
||||
$urlParts = explode('/', $requestUri);
|
||||
|
||||
if($urlParts[1] === 'faculty'){
|
||||
$slug = $urlParts[2];
|
||||
} else{
|
||||
$slug = $urlParts[1];
|
||||
}
|
||||
|
||||
$querySlug = explode('.', $slug)[0];
|
||||
// echo $querySlug;
|
||||
$fileName = $slug;
|
||||
|
||||
try {
|
||||
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$stmt = $conn->prepare("SELECT * FROM `scc24` WHERE `slug` = '".$querySlug."'");
|
||||
$stmt->execute();
|
||||
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if(isset($content[0]['content']) && $content[0]['content'])
|
||||
$pageContent = '<div class="container mx-auto" style="">
|
||||
<div class="">'.$content[0]['content'].'</div>
|
||||
</div>';
|
||||
else $pageContent = '
|
||||
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 100px 0;"><p style="text-align: center; font-size: 30px; font-weight: bold;">Page not found (404).</p>
|
||||
<a href="/">Back to home</a>
|
||||
</div>
|
||||
';
|
||||
} catch (PDOException $e) {
|
||||
$in_page_message = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
|
||||
// Render page content here
|
||||
echo $pageContent;
|
||||
|
||||
$footerContent = file_get_contents('./.hta_footer.php');
|
||||
|
||||
if($urlParts[1] === 'faculty'){
|
||||
$filePath = __DIR__ . '/' . $fileName;
|
||||
// echo $filePath;
|
||||
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
||||
} else{
|
||||
$filePath = __DIR__ . $fileName;
|
||||
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
||||
}
|
||||
|
||||
|
||||
file_put_contents($filePath, $totalPageContent);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user