Created
October 1, 2014 13:06
-
-
Save bfritscher/e39210a8d64f46469d44 to your computer and use it in GitHub Desktop.
php service that shows headers of POST and GET
This file contains hidden or 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 | |
function keyArrayToLi($key, $array){ | |
return keyValOrArrayToLi($key, isset($array[$key]) ? $array[$key] : ""); | |
} | |
function keyValOrArrayToLi($key, $val, $escape_key=true, $escape_val=true){ | |
if(is_array($val)){ | |
$html = ""; | |
foreach($val as $sub_val){ | |
$html .= keyValToLi($key, $sub_val, $escape_key, $escape_val); | |
} | |
return $html; | |
}else{ | |
return keyValToLi($key, $val, $escape_key, $escape_val); | |
} | |
} | |
function keyValToLi($key, $val, $escape_key=true, $escape_val=true){ | |
return '<li><span class="key">'. ($escape_key ? htmlspecialchars($key) : $$key) . '</span><span class="separator"> : </span><span class="val">' . ($escape_val ? htmlspecialchars($val) : $val) . "</span></li>\n"; | |
} | |
function liIfEmpty($array){ | |
if(empty($array)){ | |
echo '<li class="empty">-</li>'; | |
} | |
} | |
$http_selection = array('SERVER_PROTOCOL', | |
'REQUEST_METHOD', | |
'HTTP_USER_AGENT', | |
'HTTP_ACCEPT', | |
'HTTP_ACCEPT_ENCODING', | |
'HTTP_ACCEPT_LANGUAGE', | |
'HTTP_ACCEPT_CHARSET', | |
'HTTP_CONNECTION', | |
'HTTP_REFERER', | |
'REMOTE_ADDR', | |
'REMOTE_PORT'); | |
$file_select = array('name', 'type', 'size'); | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Echo</title> | |
<style type="text/css"> | |
<!-- | |
*{ | |
margin: 0; | |
padding: 0; | |
} | |
body { | |
background:lightgrey; | |
font-family: Arial, Helvetica, sans-serif; | |
} | |
h1{ | |
color: #a60000; | |
margin: 0.5em 0 0 1em; | |
display:block; | |
} | |
.type { | |
} | |
.type h2 { | |
color: #a60000; | |
border: 1px black solid; | |
border-bottom: none; | |
background: #eee; | |
padding: 0.3em; margin: 24px 24px 0px 24px; | |
text-align: center; | |
width: 100px; | |
} | |
.type ul, .type textarea { | |
border: 1px black solid; | |
background: #eee; | |
padding: 0.5em; margin: 0px 24px 24px 24px; | |
width:800px; | |
list-style-type:none; | |
} | |
.type ul li { | |
clear: left; | |
} | |
.key, .separator, .val { | |
display:block; | |
padding:0.3em; | |
} | |
.key, .separator { | |
float:left; | |
} | |
.key { | |
width:230px; | |
text-align:right; | |
font-weight:bold; | |
} | |
#files ul li span.val ul{ | |
width: 740px; | |
} | |
#files ul li span.val ul li span.val{ | |
margin-left: 55px; | |
} | |
.hidden{ | |
display:none; | |
} | |
textarea{ | |
width: 100%; | |
min-height: 200px; | |
} | |
--> | |
</style> | |
</head> | |
<body> | |
<h1>Echo Form variables and HTTP parameters</h1> | |
<div id="get" class="type <?php if($_SERVER['REQUEST_METHOD'] <> 'GET') echo 'hidden'?>"> | |
<h2>GET</h2> | |
<ul> | |
<?php | |
liIfEmpty($_GET); | |
foreach($_GET as $key => $val){ | |
echo keyArrayToLi($key, $_GET); | |
} | |
?> | |
</ul> | |
</div> | |
<div id="post" class="type <?php if($_SERVER['REQUEST_METHOD'] <> 'POST') echo 'hidden'?>"> | |
<h2>POST</h2> | |
<ul> | |
<?php | |
liIfEmpty($_POST); | |
foreach($_POST as $key => $val){ | |
echo keyArrayToLi($key, $_POST); | |
} | |
?> | |
</ul> | |
</div> | |
<div id="files" class="type <?php if(empty($_FILES)) echo 'hidden'?>"> | |
<h2>FILES</h2> | |
<ul> | |
<?php | |
liIfEmpty($_FILES); | |
foreach($_FILES as $key => $file){ | |
$val = "<ul>"; | |
foreach($file_select as $f_key){ | |
$val .= keyArrayToLi($f_key, $file); | |
} | |
$val .= "</ul>"; | |
echo keyValToLi($key, $val, true, false); | |
} | |
?> | |
</ul> | |
</div> | |
<div id="http" class="type"> | |
<h2>HTTP</h2> | |
<ul> | |
<?php | |
foreach($http_selection as $key){ | |
echo keyArrayToLi($key, $_SERVER); | |
} | |
?> | |
</ul> | |
</div> | |
<div class="type"> | |
<h2>DEBUG</h2> | |
<textarea> | |
<?php | |
foreach(getallheaders() as $k => $v){ | |
echo $k . ": " . $v . "\n"; | |
} | |
?> | |
</textarea> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment