Created
February 15, 2021 07:02
-
-
Save shtrom/c1c9d533667b2e9af21b3d7e15e1aa1d to your computer and use it in GitHub Desktop.
A simple echo page in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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