Fixed the getIP command so that the clients IP is always returned, even behind multiple proxies.

Fixed indentation.
This commit is contained in:
Maurice Meyer 2016-04-20 14:59:06 +02:00
parent c7ff6326ee
commit ab84439c1a

View file

@ -59,13 +59,14 @@ if(filter_input(INPUT_SERVER, "REQUEST_METHOD") == "GET") {
echo json_encode($return);
exit();
} else if(filter_input(INPUT_GET, "action") == "getIp") {
// If we are behind a proxy, return the proxies IP address
if(filter_input(INPUT_SERVER, "HTTP_X_FORWARDED_FOR") != null){
$return['ip'] = filter_input(INPUT_SERVER, "HTTP_X_FORWARDED_FOR");
}
else {
$return['ip'] = filter_input(INPUT_SERVER, "REMOTE_ADDR");
}
// If we are behind a proxy, return the first IP the request was forwarded for.
if(filter_input(INPUT_SERVER, "HTTP_X_FORWARDED_FOR") != null){
$return['ip'] = explode(",", filter_input(INPUT_SERVER, "HTTP_X_FORWARDED_FOR"))[0];
} else {
$return['ip'] = filter_input(INPUT_SERVER, "REMOTE_ADDR");
}
echo json_encode($return);
exit();
}