-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreply.php
More file actions
34 lines (34 loc) · 1.23 KB
/
reply.php
File metadata and controls
34 lines (34 loc) · 1.23 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
<?php
session_start();
if($_SERVER['REQUEST_METHOD'] === 'POST') {
if($_SESSION['LOGGED_IN']) {
$posts = json_decode(file_get_contents("topics.json"), true);
array_push($posts[htmlspecialchars($_POST['topic-name'])], array('author' => $_SESSION['user'], 'content' => str_replace("\n","<br>",htmlspecialchars($_POST['content']))));
file_put_contents("topics.json", json_encode($posts));
header("Location: /topic.php?topic=" . urlencode(htmlspecialchars($_POST['topic-name'])));
exit();
} else {
http_response_code(401);
echo "401: You need to be logged in to post";
}
}
?>
<?php if(!($_SERVER['REQUEST_METHOD'] === 'POST') && $_SESSION['LOGGED_IN']): ?>
<form id="post-form" method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="text"
name="topic-name"
placeholder="Topic Name"
value="<?php if($_GET['topic'] ?? null) echo $_GET['topic']; ?>"
<?php if($_GET['topic'] ?? null) {
echo "readonly";
}
?>
/> <br>
<textarea form="post-form" name="content" placeholder="Post Content"></textarea> <br>
<input type="submit"/>
</form>
<?php else: ?>
<?php http_response_code(401); ?>
Please login to post.
<?php endif; ?>
<link rel="stylesheet" href="/proconfig/topic-ui.css">