3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getUserIP() { $ipas = null; $keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'); foreach($keys as $key) { $value = isset($_SERVER[$key]) ? $_SERVER[$key] : null; if(isset($value)) { foreach(explode(',', $value) as $ip) { if(false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $ipas = $ip; } } } } return $ipas; } echo getUserIp();
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0