-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
56 lines (48 loc) · 1.6 KB
/
index.php
File metadata and controls
56 lines (48 loc) · 1.6 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
<?php
if (!isset($_REQUEST['url'])) {
http_response_code(400);
echo "No URL specified.";
exit();
}
$target = urldecode($_REQUEST['url']);
if (!filter_var($target, FILTER_VALIDATE_URL)) {
http_response_code(400);
echo "Invalid URL.";
exit();
}
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'POST') {
$rawBody = file_get_contents('php://input');
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (stripos($contentType, 'application/json') !== false) {
$ch = curl_init($target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($rawBody)
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $rawBody);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
http_response_code($status);
echo $response;
exit();
} else {
echo '<html><body>';
echo '<form id="redirectForm" method="POST" action="' . htmlspecialchars($target) . '">';
foreach ($_POST as $key => $value) {
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
echo '<input type="hidden" name="' . $key . '" value="' . $value . '">';
}
echo '</form>';
echo '<script>document.getElementById("redirectForm").submit();</script>';
echo '</body></html>';
exit();
}
} else {
header("Location: $target");
exit();
}