-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.php
75 lines (61 loc) · 1.53 KB
/
index.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
<?php
$fields = [
"CONTENT_LENGTH",
"CONTENT_TYPE",
"DOCUMENT_ROOT",
"DOCUMENT_URI",
"GATEWAY_INTERFACE",
"HTTPS",
"ORIG_PATH_INFO",
"PATH_INFO",
"QUERY_STRING",
"REMOTE_ADDR",
"REMOTE_HOST",
"REMOTE_PORT",
"REQUEST_METHOD",
"REQUEST_URI",
"SCRIPT_FILENAME",
"SCRIPT_NAME",
"SERVER_ADDR",
"SERVER_ADMIN",
"SERVER_NAME",
"SERVER_PORT",
"SERVER_PROTOCOL",
"SERVER_SOFTWARE",
];
foreach ($fields as $field) {
$display[$field] = $_SERVER[$field] ?? "__";
}
$headers = [];
foreach ($_SERVER as $key => $value) {
if (0 === strpos($key, 'HTTP_')) {
$headers[$key] = $value;
}
}
ksort($headers);
ksort($display);
$requestBody = file_get_contents("php://input");
$date = date('Y-m-d H:i:s');
$content = "Hey! It works!\n"
.json_encode([
'Date' => $date,
'Server parameters' => $display,
'Request headers' => $headers,
'Request body' => $requestBody,
], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$logs = <<<LOG
===========================
Date: {$date}
Content:
{$content}
===========================
LOG;
file_put_contents('_local_logs.txt', $logs, FILE_APPEND);
header('Content-Type: text/plain');
header('Content-Length: '.strlen($content));
header('X-Some-Random-Header: some-random-value');
echo $content;
file_put_contents("php://stderr", "This content should be written to stderr.\n", FILE_APPEND);
if (\function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}