-
Notifications
You must be signed in to change notification settings - Fork 1
/
post.php
76 lines (52 loc) · 1.9 KB
/
post.php
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
<?php
header("X-Frame-Options: DENY");
header("Content-Security-Policy: frame-ancestors 'none'", false);
header("Content-Type: application/json; charset=UTF-8");
session_start();
function scrub($input) {
$splitted = explode('<', $input);
$splitted = implode('<', $splitted);
$splitted = explode('>', $splitted);
$splitted = implode('>', $splitted);
return $splitted;
}
include('config.php');
include('endecr.php');
$inps = $_POST['inkay'];
if ($inps == $passw) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['type'] == "nojs") {
$data['name'] = $_POST['name'];
$data['message'] = $_POST['message'];
header('Location: index.php#message');
} else {
$data = json_decode(file_get_contents("php://input"), false);
print_r($data);
}
}
$data = (array) $data;
date_default_timezone_set("UTC");
$chat = fopen('chat.txt', 'a') or die('Error upon opening file');
$name = 'anonymous';
if ($_POST['name'] !== '') {
$name = $data['name'];
}
$message = scrub($data['message']);
$name = scrub($name);
$name = explode(' ', $name);
$name = implode('_', $name);
$_SESSION['name'] = $name;
$text = '<name>' . $name . '</name><br/><br/>' . '<message>' . $message . '</message><br/><br/><date>' . date("Y-m-d") . ' ' . date("H:i:s") . "</date><br/>\n";
$text_paus = encrypt_decrypt("encrypt", $text, $passw);
$text = $text_paus . "\n";
if ($message !== '') {
$status = 'Success!';
fwrite($chat, $text);
}
else {
$status = 'Error. No message';
}
echo $status;
fclose($chat);
}
?>