aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Briskin <sergey@briskin.org>2014-03-08 00:15:57 +0400
committerSergey Briskin <sergey@briskin.org>2014-03-08 00:15:57 +0400
commita7427a211b7cc26f6c1fc2abc439300248c7f641 (patch)
treefd17c4d0c95d2913572a86febb74bd7e30bc8243
parent3b90c5f28c40f71552e36209b5b3eaadceb79cec (diff)
downloadifconfig.php-a7427a211b7cc26f6c1fc2abc439300248c7f641.tar.gz
ifconfig.php-a7427a211b7cc26f6c1fc2abc439300248c7f641.tar.bz2
ifconfig.php-a7427a211b7cc26f6c1fc2abc439300248c7f641.zip
modified: README.md
modified: ifconfig.php
-rw-r--r--README.md9
-rw-r--r--ifconfig.php35
2 files changed, 20 insertions, 24 deletions
diff --git a/README.md b/README.md
index cd295ab..2119f50 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,15 @@
ifconfig.php
============
-**Simple PHP script to show IP, UserAgent and other info**
+**Simple PHP script to show IP-address, UserAgent and other info**
Added all basic features, such as output in HTML, plain text, XML and JSON.
-By default it will be in HTML. Use 'f=' arg to select another output format.
-Also it is possible to request single value by defining 'q=' arg.
+By default it will be in HTML. Also it is possible to request single value.
Visit some of the links below to view it in action:
-* [all in plain text](http://briskin.org/ifconfig.php?f=text)
-* [all in xml](http://briskin.org/ifconfig.php?f=xml)
+* [all in plain text](http://briskin.org/ifconfig.php?q=text)
+* [all in xml](http://briskin.org/ifconfig.php?q=xml)
* [useragent only](http://briskin.org/ifconfig.php?q=ua)
P.s.
diff --git a/ifconfig.php b/ifconfig.php
index 094aede..3cf3b05 100644
--- a/ifconfig.php
+++ b/ifconfig.php
@@ -2,7 +2,7 @@
/*
* User connection info
*
- * Version: 1.0 2014/03/06
+ * Version: 1.1 2014/03/08
* License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html)
*
* Copyright (C) 2014 Sergey Briskin (http://briskin.org)
@@ -43,29 +43,22 @@ $user = array(
'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']))))));
+// Check request (ex. ifconfig.php?q=ip)
+$query=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]);
+// Return single value on request & die
+if (isset($query) && !empty($user[$query]) && array_key_exists($query, $user)) {
+ die($user[$query]."\n");
}
-unset($rqst);
-
-// Return full output in one of supported formats (xml, json, plain text. default: html)
-if (isset($type) && ($type=="text")) {
+// Return full output in one of supported formats (html, text, xml, json. default: html)
+elseif (isset($query) && ($query=="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")) {
+
+} elseif (isset($query) && ($query=="xml")) {
header('Content-Type: text/xml');
// Function for SimpleXML creation
@@ -80,6 +73,10 @@ function array_to_xml(array $arr, SimpleXMLElement $xml)
}
echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
+} elseif (isset($query) && ($query=="json")) {
+ header('Content-Type: application/json');
+ die(json_encode($user));
+
} else {
header('Content-Type: text/html');
?><!DOCTYPE html>
@@ -95,7 +92,7 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
font-size: .9em;
}
p {
- font-family: "Source Code Pro", "Courier New", "Consolas", "Terminal", "Droid Mono", fixed;
+ font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed;
line-height: 1em;
}
.small, .small > a {
@@ -120,4 +117,4 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
<?
}
die();
-?>
+?> \ No newline at end of file