Commit a7427a211b

a7427a211b7cc26f6c1fc2abc439300248c7f641

parent: 3b90c5f28c

Unsigned

Sergey Briskin <sergey@briskin.org> · 2014-03-07 20:15 UTC

	modified:   README.md
	modified:   ifconfig.php

Layout: unified · split

README.md +4 −5
@@ -1,16 +1,15 @@
11ifconfig.php
22============
33
4**Simple PHP script to show IP, UserAgent and other info**
4**Simple PHP script to show IP-address, UserAgent and other info**
55
66
77Added all basic features, such as output in HTML, plain text, XML and JSON.
8By default it will be in HTML. Use 'f=' arg to select another output format.
9Also it is possible to request single value by defining 'q=' arg.
8By default it will be in HTML. Also it is possible to request single value.
109
1110Visit some of the links below to view it in action:
12* [all in plain text](http://briskin.org/ifconfig.php?f=text)
13* [all in xml](http://briskin.org/ifconfig.php?f=xml)
11* [all in plain text](http://briskin.org/ifconfig.php?q=text)
12* [all in xml](http://briskin.org/ifconfig.php?q=xml)
1413* [useragent only](http://briskin.org/ifconfig.php?q=ua)
1514
1615P.s.
ifconfig.php +16 −19
@@ -2,7 +2,7 @@
22/*
33 * User connection info
44 *
5 * Version: 1.0 2014/03/06
5 * Version: 1.1 2014/03/08
66 * License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html)
77 *
88 * Copyright (C) 2014 Sergey Briskin (http://briskin.org)
@@ -43,29 +43,22 @@ $user = array(
4343 'dnt' => $_SERVER['HTTP_DNT']
4444 );
4545
46// Single HTTP-HEADER value request (ex. ifconfig.php?q=ip)
47$rqst=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['q']))))));
46// Check request (ex. ifconfig.php?q=ip)
47$query=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['q']))))));
4848
49// Output format (ex. ifconfig.php?f=xml)
50$type=trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($_GET['f']))))));
51
52// Return Single value on request & die
53if (isset($rqst) && !empty($user[$rqst]) && array_key_exists($rqst, $user)) {
54 die($user[$rqst]);
49// Return single value on request & die
50if (isset($query) && !empty($user[$query]) && array_key_exists($query, $user)) {
51 die($user[$query]."\n");
5552}
56unset($rqst);
57
58// Return full output in one of supported formats (xml, json, plain text. default: html)
59if (isset($type) && ($type=="text")) {
53// Return full output in one of supported formats (html, text, xml, json. default: html)
54elseif (isset($query) && ($query=="text")) {
6055 header('Content-Type: text/plain');
6156 foreach($user as $key => $value) {
6257 echo $key.": ".$value."\n";
6358 }
6459 die();
65} elseif (isset($type) && ($type=="json")) {
66 header('Content-Type: application/json');
67 die(json_encode($user));
68} elseif (isset($type) && ($type=="xml")) {
60
61} elseif (isset($query) && ($query=="xml")) {
6962 header('Content-Type: text/xml');
7063
7164// Function for SimpleXML creation
@@ -80,6 +73,10 @@ function array_to_xml(array $arr, SimpleXMLElement $xml)
8073}
8174echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
8275
76} elseif (isset($query) && ($query=="json")) {
77 header('Content-Type: application/json');
78 die(json_encode($user));
79
8380} else {
8481 header('Content-Type: text/html');
8582?><!DOCTYPE html>
@@ -95,7 +92,7 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
9592 font-size: .9em;
9693 }
9794 p {
98 font-family: "Source Code Pro", "Courier New", "Consolas", "Terminal", "Droid Mono", fixed;
95 font-family: "Source Code Pro", "Droid Mono", "Courier New", "Consolas", "Terminal", fixed;
9996 line-height: 1em;
10097 }
10198 .small, .small > a {
@@ -120,4 +117,4 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML();
120117<?
121118}
122119die();
123?>
120?>
\ No newline at end of file