-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
77 lines (65 loc) · 1.88 KB
/
Copy pathpost.php
File metadata and controls
77 lines (65 loc) · 1.88 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require __DIR__ . '/vendor/autoload.php';
use Defuse\Crypto\KeyProtectedByPassword;
use Defuse\Crypto\Crypto;
session_start();
$username_in_use = False;
if (!$_SESSION['authorised']) {
# Not logged in, you can't post now, silly!
header("Location: index.php");
}
if (
isset($_POST['entry_title']) and
isset($_POST['journal_entry'])
) {
$db = new mysqli("localhost", "nick", "nickmysql", "journal_site");
if ($db->connect_error) {
die("Faatal backend error: " . $db->connect_error);
}
# encrypt entry
$entry_title_enc = Crypto::encrypt($_POST["entry_title"], $_SESSION["user_key"]);
$journal_entry_enc = Crypto::encrypt($_POST["journal_entry"], $_SESSION["user_key"]);
$stmt = $db->prepare("INSERT INTO entries (entry_title, entry_text, entry_author_id) VALUES (?, ?, ?)");
$stmt->bind_param(
"ssi",
$entry_title_enc,
$journal_entry_enc,
$_SESSION['user_id']
);
$post_ok = $stmt->execute();
if ($post_ok) {
header("Location: index.php");
} else {
die("Failed to add entry!");
}
exit();
}
?>
<html>
<head>
<title>Registration</title>
</head>
<body>
<?php
if (!file_exists("/var/www/state/journal_registration_open")) {
# Failsafe in case someone guesses the url - it's not hard
echo "
<p>sorry, registration is not open at this time...</p>
</body>
</html>
";
exit();
}
?>
<h1>Write in your journal</h1>
<form action="post.php" method="POST">
<p>Post title:<input type="text" name="entry_title" /></p>
<p>
Write your entry here:<br>
<textarea id="journal_entry" name="journal_entry" rows="24" cols="80"></textarea>
</p>
<input type="submit" name="submitButton" value="Save" />
<a href="index.php">Cancel</a>
</form>
</body>
</html>