Skip to content

Instantly share code, notes, and snippets.

@shtrom
Created February 15, 2021 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shtrom/c1c9d533667b2e9af21b3d7e15e1aa1d to your computer and use it in GitHub Desktop.
Save shtrom/c1c9d533667b2e9af21b3d7e15e1aa1d to your computer and use it in GitHub Desktop.
A simple echo page in PHP
<?php
/** A simple echo page in PHP
*
* It just outputs the request it received back, including HTTP headers.
*/
if (!function_exists('getallheaders')) {
// Polyfill for PHP<7.3
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $key => $value) {
if (strpos($key, 'HTTP_') === 0) {
$chunks = explode('_', $key);
$header = '';
for ($i = 1; $y = sizeof($chunks) - 1, $i < $y; $i++) {
$header .= ucfirst(strtolower($chunks[$i])).'-';
}
$header .= ucfirst(strtolower($chunks[$i])).': '.$value;
$headers .= $header . PHP_EOL;
}
}
return $headers;
}
}
header("Content-Type: text/plain");
echo "{$_SERVER['REQUEST_METHOD']} {$_SERVER['REQUEST_URI']} {$_SERVER['SERVER_PROTOCOL']}" . PHP_EOL;
echo getallheaders();
echo PHP_EOL;
echo file_get_contents('php://input');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment