HTTP Request Bin
<?php | |
/** | |
* RequestBin - Captures and displays HTTP requests | |
* @author adrian7 | |
* @version 1.1 | |
*/ | |
//TODO (1) Parse request data in a nice way | |
//TODO (2) Alternative nice display alongside raw | |
$method = $_SERVER['REQUEST_METHOD']; | |
function extract_data($contentType, $raw=TRUE){ | |
$data = file_get_contents('php://input'); | |
$parsed = NULL; | |
mb_parse_str($data, $parsed); | |
if( $raw ) | |
//just return raw data | |
return strval( $data ); | |
$contentType = @explode($contentType, ';'); | |
$contentType = strtolower( $contentType[0] ); | |
var_dump( $parsed ); | |
} | |
function parse_request_headers() { | |
$headers = []; | |
foreach($_SERVER as $key => $value) { | |
if ( substr($key, 0, 5) <> 'HTTP_' ) { | |
continue; | |
} | |
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5))))); | |
$headers[$header] = $value; | |
} | |
return $headers; | |
} | |
function get_http_request(){ | |
$data = extract_data( NULL ); | |
$lines = ( $_SERVER['REQUEST_METHOD'] ); | |
$lines.= (' ' . $_SERVER['REQUEST_URI'] ); | |
$lines.= (' ' . $_SERVER['SERVER_PROTOCOL'] . PHP_EOL ); | |
$headers = parse_request_headers(); | |
if( count($headers) ) foreach ($headers as $name=>$value) | |
$lines.= ( PHP_EOL . $name . ': ' . strval($value) ); | |
if( $data ) { | |
$lines.= ( PHP_EOL . PHP_EOL ); | |
$lines.= $data; | |
} | |
return trim($lines); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="utf-8"/> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<meta name="credits" content="https://www.studentmoneysaver.co.uk/team/"/> | |
<meta name="description" content="We specialise in student discounts, deals & free stuff, as well as ways to make money quickly. Plus, everything you need to know about student finance, made simple."/> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row header"> | |
<div class="col-lg-12"> | |
<h1><i class="fa fa-trash-o"></i> HTTP Request Bin</h1> | |
</div> | |
</div> | |
<hr/> | |
<div class="row"> | |
<div class="col-lg-12"> | |
<h3> | |
Received <strong><?php echo $_SERVER['REQUEST_METHOD']; ?></strong> request from | |
<?php | |
if( isset($_SERVER['HTTP_REFERER']) ) | |
echo $_SERVER['HTTP_REFERER']; | |
else | |
echo "self"; | |
?> | |
</h3> | |
<br/> | |
<pre style="font-size: 1em;"><?php echo get_http_request(); ?></pre> | |
</div> | |
</div> | |
</div> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" property="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"/> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" property="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
<style media="screen" type="text/css" scoped> | |
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,700,400italic,700italic'); | |
body{ | |
background: #eaeaea; | |
color: #0e0803; | |
font-family: 'Fira Sans', Arial, Helvetica, sans-serif; | |
font-size: 2em; | |
} | |
.alert{ | |
color: #0e0803; | |
} | |
</style> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment