Commit a7427a211b
Unsigned
Layout: unified · split
README.md +4 −5
| @@ -1,16 +1,15 @@ | ||
| 1 | 1 | ifconfig.php |
| 2 | 2 | ============ |
| 3 | 3 | |
| 4 | **Simple PHP script to show IP, UserAgent and other info** | |
| 4 | **Simple PHP script to show IP-address, UserAgent and other info** | |
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | Added all basic features, such as output in HTML, plain text, XML and JSON. |
| 8 | By default it will be in HTML. Use 'f=' arg to select another output format. | |
| 9 | Also it is possible to request single value by defining 'q=' arg. | |
| 8 | By default it will be in HTML. Also it is possible to request single value. | |
| 10 | 9 | |
| 11 | 10 | Visit 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) | |
| 14 | 13 | * [useragent only](http://briskin.org/ifconfig.php?q=ua) |
| 15 | 14 | |
| 16 | 15 | P.s. |
ifconfig.php +16 −19
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | * User connection info |
| 4 | 4 | * |
| 5 | * Version: 1.0 2014/03/06 | |
| 5 | * Version: 1.1 2014/03/08 | |
| 6 | 6 | * License: GPL v2 (https://www.gnu.org/licenses/gpl-2.0.html) |
| 7 | 7 | * |
| 8 | 8 | * Copyright (C) 2014 Sergey Briskin (http://briskin.org) |
| @@ -43,29 +43,22 @@ $user = array( | ||
| 43 | 43 | 'dnt' => $_SERVER['HTTP_DNT'] |
| 44 | 44 | ); |
| 45 | 45 | |
| 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'])))))); | |
| 48 | 48 | |
| 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 | |
| 53 | if (isset($rqst) && !empty($user[$rqst]) && array_key_exists($rqst, $user)) { | |
| 54 | die($user[$rqst]); | |
| 49 | // Return single value on request & die | |
| 50 | if (isset($query) && !empty($user[$query]) && array_key_exists($query, $user)) { | |
| 51 | die($user[$query]."\n"); | |
| 55 | 52 | } |
| 56 | unset($rqst); | |
| 57 | ||
| 58 | // Return full output in one of supported formats (xml, json, plain text. default: html) | |
| 59 | if (isset($type) && ($type=="text")) { | |
| 53 | // Return full output in one of supported formats (html, text, xml, json. default: html) | |
| 54 | elseif (isset($query) && ($query=="text")) { | |
| 60 | 55 | header('Content-Type: text/plain'); |
| 61 | 56 | foreach($user as $key => $value) { |
| 62 | 57 | echo $key.": ".$value."\n"; |
| 63 | 58 | } |
| 64 | 59 | 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")) { | |
| 69 | 62 | header('Content-Type: text/xml'); |
| 70 | 63 | |
| 71 | 64 | // Function for SimpleXML creation |
| @@ -80,6 +73,10 @@ function array_to_xml(array $arr, SimpleXMLElement $xml) | ||
| 80 | 73 | } |
| 81 | 74 | echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); |
| 82 | 75 | |
| 76 | } elseif (isset($query) && ($query=="json")) { | |
| 77 | header('Content-Type: application/json'); | |
| 78 | die(json_encode($user)); | |
| 79 | ||
| 83 | 80 | } else { |
| 84 | 81 | header('Content-Type: text/html'); |
| 85 | 82 | ?><!DOCTYPE html> |
| @@ -95,7 +92,7 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); | ||
| 95 | 92 | font-size: .9em; |
| 96 | 93 | } |
| 97 | 94 | 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; | |
| 99 | 96 | line-height: 1em; |
| 100 | 97 | } |
| 101 | 98 | .small, .small > a { |
| @@ -120,4 +117,4 @@ echo array_to_xml($user, new SimpleXMLElement('<info/>'))->asXML(); | ||
| 120 | 117 | <? |
| 121 | 118 | } |
| 122 | 119 | die(); |
| 123 | ?> | |
| 120 | ?> | |
| \ No newline at end of file | ||