PHP Proper Coding – Avoiding Access The Global Variables, Example: Client-IP From $_SERVER

filter-input provides the proper way of accessing $_SERVER (and other)

<?php

$ips = [
filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_FOR', FILTER_SANITIZE_SPECIAL_CHARS)
,filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_SPECIAL_CHARS)
,filter_input(INPUT_SERVER, 'HTTP_CLIENT_IP', FILTER_SANITIZE_SPECIAL_CHARS)
];

$ips = array_filter($ips, function($ip){ return null !== $ip; });

echo json_encode(array_values($ips));

?>