Skip to content

Instantly share code, notes, and snippets.

@aplneto
Last active October 24, 2024 15:02
Show Gist options
  • Save aplneto/433d265c70a160373c52ae2362a52136 to your computer and use it in GitHub Desktop.
Save aplneto/433d265c70a160373c52ae2362a52136 to your computer and use it in GitHub Desktop.
PHP Request Reflection Server
RewriteEngine On
RewriteRule ^ index.php [L]
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^config\.php$ - [F]
RewriteRule .* - [e=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
<?php
// Returns the content of HTTP Requests received
// Set content-type to plaintext to avoid XSS problems
header("Content-Type: text/plain");
// Request Method, URL and Protocol
echo "{$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']} {$_SERVER['SERVER_PROTOCOL']}\n";
// Request Headers
foreach (apache_request_headers() as $header => $value) {
echo "$header: $value\n";
}
// x-www-form-urlencoded post data
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$post_data_array = [];
foreach ($_POST as $key => $value) {
array_push($post_data_array, "$key=$value");
}
echo "\n\n" . join("&", $post_data_array);
}
// other post data
$json = file_get_contents('php://input');
if ($json) {
echo $json;
}
// TODO add multipart/form-data support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment