-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
executable file
·105 lines (100 loc) · 4.05 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Chronolabs REST Short Link URIs API
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Chronolabs Cooperative http://au.syd.labs.coop
* @license Academic + GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @package api
* @since 2.2.1
* @author Simon Roberts <[email protected]>
* @version 2.2.1
* @subpackage shortening-url
* @description Short Link URIs API
* @link http://internetfounder.wordpress.com
* @link http://sourceoforge.net/projects/chronolabsapis/files/jump.labs.coop
* @link https://github.com/Chronolabs-Cooperative/Jump-API-PHP
*/
error_reporting(E_ALL);
ini_set('display_errors', true);
if (!function_exists("getIP")) {
/* function whitelistGetIP()
*
* get the True IPv4/IPv6 address of the client using the API
* @author Simon Roberts (Chronolabs) [email protected]
*
* @param boolean $asString Whether to return an address or network long integer
*
* @return mixed
*/
function getIP($asString = true){
// Gets the proxy ip sent by the user
$proxy_ip = '';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else
if (!empty($_SERVER['HTTP_X_FORWARDED'])) {
$proxy_ip = $_SERVER['HTTP_X_FORWARDED'];
} else
if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) {
$proxy_ip = $_SERVER['HTTP_FORWARDED_FOR'];
} else
if (!empty($_SERVER['HTTP_FORWARDED'])) {
$proxy_ip = $_SERVER['HTTP_FORWARDED'];
} else
if (!empty($_SERVER['HTTP_VIA'])) {
$proxy_ip = $_SERVER['HTTP_VIA'];
} else
if (!empty($_SERVER['HTTP_X_COMING_FROM'])) {
$proxy_ip = $_SERVER['HTTP_X_COMING_FROM'];
} else
if (!empty($_SERVER['HTTP_COMING_FROM'])) {
$proxy_ip = $_SERVER['HTTP_COMING_FROM'];
}
if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) {
$the_IP = $regs[0];
} else {
$the_IP = $_SERVER['REMOTE_ADDR'];
}
$the_IP = ($asString) ? $the_IP : ip2long($the_IP);
return $the_IP;
}
}
$data = array('time' => time(), 'ip' => getIP(true), 'www-path' => basename(__DIR__), 'server' => $_SERVER, 'get' => $_GET, 'post' => $_POST);
$response = (isset($_REQUEST['response'])?$_REQUEST['response']:'json');
if (function_exists("http_response_code"))
if (isset($data['code']) && !empty($data['code'])) {
http_response_code($data['code']);
unset($data['code']);
} else {
http_response_code(201);;
}
// Send Responses
switch ($response)
{
case 'php':
header('Content-type: application/php');
die("<?php\n\nreturn " . var_export($data) . ";\n\n?>");
break;
case 'json':
header('Content-type: application/json');
die(json_encode($data));
break;
case 'serial':
header('Content-type: text/html');
die(serialize($data));
break;
case 'xml':
header('Content-type: application/xml');
$dom = new XmlDomConstruct('1.0', 'utf-8');
$dom->fromMixed(array('root'=>$data));
die($dom->saveXML());
break;
}
?>