-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
52 lines (38 loc) · 1.39 KB
/
page.php
File metadata and controls
52 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php # page.php - Script 9.9
// This page displays a single page of content.
// Need the utilities file:
require('includes/utilities.inc.php');
try {
// Validate the page ID:
if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) {
throw new Exception('Erro 1.');
}
// Fetch the page from the database:
$q = 'SELECT id, creatorId, title, content, DATE_FORMAT(dateAdded, "%e %M %Y") AS dateAdded FROM pages WHERE id=:id';
$stmt = $pdo->prepare($q);
$r = $stmt->execute(array(':id' => $_GET['id']));
// If the query ran okay, fetch the record into an object:
if ($r) {
$stmt->setFetchMode(PDO::FETCH_CLASS, 'Page');
$page = $stmt->fetch();
// Confirm that it exists:
if ($page) {
// Set the browser title to the page title:
$pageTitle = $page->getTitle();
// Create the page:
include('includes/header.inc.php');
include('views/page.html');
} else {
throw new Exception('Erro 2.');
}
} else {
throw new Exception('Error 3.');
}
} catch (Exception $e) { // Catch generic Exceptions.
$pageTitle = 'Error!';
include('includes/header.inc.php');
include('views/error.html');
}
// Include the footer:
include('includes/footer.inc.php');
?>