3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } $ipinfo = ip_info($_SERVER['REMOTE_ADDR']); echo $ipinfo['country_code'];
Output for 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 66 Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 5 Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /in/9go2v on line 13 Warning: Trying to access array offset on null in /in/9go2v on line 67
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 66 Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 5 Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /in/9go2v on line 13 Warning: Trying to access array offset on null in /in/9go2v on line 67
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 66 Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 5 Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /in/9go2v on line 13 Warning: Trying to access array offset on value of type null in /in/9go2v on line 67
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 66 Warning: Undefined array key "REMOTE_ADDR" in /in/9go2v on line 5 Warning: Trying to access array offset on value of type null in /in/9go2v on line 67
Output for 7.4.0 - 7.4.33
Notice: Undefined index: REMOTE_ADDR in /in/9go2v on line 66 Notice: Undefined index: REMOTE_ADDR in /in/9go2v on line 5 Notice: Trying to access array offset on value of type null in /in/9go2v on line 67
Output for 7.3.32 - 7.3.33
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31
Notice: Undefined index: REMOTE_ADDR in /in/9go2v on line 66 Notice: Undefined index: REMOTE_ADDR in /in/9go2v on line 5

preferences:
183.62 ms | 403 KiB | 213 Q