From f3a30e3333def90dd17e77c09a24f40fd14cb702 Mon Sep 17 00:00:00 2001 From: Sergey Briskin Date: Fri, 7 Mar 2014 19:49:54 +0400 Subject: new file: ifconfig.php --- ifconfig.php | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 ifconfig.php diff --git a/ifconfig.php b/ifconfig.php new file mode 100644 index 0000000..094aede --- /dev/null +++ b/ifconfig.php @@ -0,0 +1,123 @@ + $_SERVER['REMOTE_ADDR'], + 'host' => (isset($_SERVER['REMOTE_ADDR']) ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : ""), + 'port' => $_SERVER['REMOTE_PORT'], + 'ua' => $_SERVER['HTTP_USER_AGENT'], + 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], + 'mime' => $_SERVER['HTTP_ACCEPT'], + 'encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], + 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], + 'connection' => $_SERVER['HTTP_CONNECTION'], + 'cache' => $_SERVER['HTTP_CACHE_CONTROL'], + 'cookie' => $_SERVER['HTTP_COOKIE'], + 'referer' => $_SERVER['HTTP_REFERER'], + 'real_ip' => $_SERVER['HTTP_X_REAL_IP'], + 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], + 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), + 'dnt' => $_SERVER['HTTP_DNT'] + ); + +// Single HTTP-HEADER value request (ex. ifconfig.php?q=ip) +$rqst=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['q'])))))); + +// Output format (ex. ifconfig.php?f=xml) +$type=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['f'])))))); + +// Return Single value on request & die +if (isset($rqst) && !empty($user[$rqst]) && array_key_exists($rqst, $user)) { + die($user[$rqst]); +} +unset($rqst); + +// Return full output in one of supported formats (xml, json, plain text. default: html) +if (isset($type) && ($type=="text")) { + header('Content-Type: text/plain'); + foreach($user as $key => $value) { + echo $key.": ".$value."\n"; + } + die(); +} elseif (isset($type) && ($type=="json")) { + header('Content-Type: application/json'); + die(json_encode($user)); +} elseif (isset($type) && ($type=="xml")) { + header('Content-Type: text/xml'); + +// Function for SimpleXML creation +function array_to_xml(array $arr, SimpleXMLElement $xml) +{ + foreach ($arr as $k => $v) { + is_array($v) + ? array_to_xml($v, $xml->addChild($k)) + : $xml->addChild($k, $v); + } + return $xml; +} +echo array_to_xml($user, new SimpleXMLElement(''))->asXML(); + +} else { + header('Content-Type: text/html'); +?> + + + + info + + + + + $value) { + echo '

'.$key.': '.$value.'

'."\n"; + } +?> +
+

Copyright © 2014 Sergey Briskin.
+Get Source code on GitHub

+ + + -- cgit v1.2.3-70-g09d2