-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview-entry.php
More file actions
52 lines (41 loc) · 1.21 KB
/
view-entry.php
File metadata and controls
52 lines (41 loc) · 1.21 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
require __DIR__ . '/vendor/autoload.php';
use Defuse\Crypto\Crypto;
session_start();
if (!$_SESSION['authorised']) {
# You need to be logged in to read posts
header("Location: index.php");
exit();
}
# try to login to database
$db = new mysqli("localhost", "nick", "nickmysql", "journal_site");
if ($db->connect_error) {
die("Fatal backend error: " . $db->connect_error);
}
# fetch entry from database
$stmt = $db->prepare("SELECT * FROM entries WHERE id = ? ORDER BY entry_timestamp DESC");
$stmt->bind_param('i', $_GET['entry']);
$stmt->execute();
$entry_data = $stmt->get_result()->fetch_assoc();
if ($entry_data['entry_author_id'] != $_SESSION['user_id']) {
# Snooping on other people's journal entries is not ok!
header("Location: index.php");
exit();
}
# decrypt entry data
$entry_title = Crypto::decrypt($entry_data['entry_title'], $_SESSION['user_key']);
$entry_text = Crypto::decrypt($entry_data['entry_text'], $_SESSION['user_key']);
?>
<html>
<head>
<title>Journal - <?php echo $entry_title; ?></title>
</head>
<body>
<h1><?php echo $entry_title; ?></h1>
<a href="index.php">Back to index</a>
<hr>
<p>
<?php echo $entry_text; ?>
</p>
</body>
</html>