Guest User

Untitled

a guest
Nov 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
  2. $output = NULL;
  3. if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
  4. $ip = $_SERVER["REMOTE_ADDR"];
  5. if ($deep_detect) {
  6. if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
  7. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  8. if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
  9. $ip = $_SERVER['HTTP_CLIENT_IP'];
  10. }
  11. }
  12. $purpose = str_replace(array("name", "n", "t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
  13. $support = array("country", "countrycode", "state", "region", "city", "location", "address");
  14. $continents = array(
  15. "AF" => "Africa",
  16. "AN" => "Antarctica",
  17. "AS" => "Asia",
  18. "EU" => "Europe",
  19. "OC" => "Australia (Oceania)",
  20. "NA" => "North America",
  21. "SA" => "South America"
  22. );
  23. if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
  24. $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
  25. if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
  26. switch ($purpose) {
  27. case "location":
  28. $output = array(
  29. "city" => @$ipdat->geoplugin_city,
  30. "state" => @$ipdat->geoplugin_regionName,
  31. "country" => @$ipdat->geoplugin_countryName,
  32. "country_code" => @$ipdat->geoplugin_countryCode,
  33. "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
  34. "continent_code" => @$ipdat->geoplugin_continentCode
  35. );
  36. break;
  37. case "address":
  38. $address = array($ipdat->geoplugin_countryName);
  39. if (@strlen($ipdat->geoplugin_regionName) >= 1)
  40. $address[] = $ipdat->geoplugin_regionName;
  41. if (@strlen($ipdat->geoplugin_city) >= 1)
  42. $address[] = $ipdat->geoplugin_city;
  43. $output = implode(", ", array_reverse($address));
  44. break;
  45. case "city":
  46. $output = @$ipdat->geoplugin_city;
  47. break;
  48. case "state":
  49. $output = @$ipdat->geoplugin_regionName;
  50. break;
  51. case "region":
  52. $output = @$ipdat->geoplugin_regionName;
  53. break;
  54. case "country":
  55. $output = @$ipdat->geoplugin_countryName;
  56. break;
  57. case "countrycode":
  58. $output = @$ipdat->geoplugin_countryCode;
  59. break;
  60. }
  61. }
  62. }
  63. return $output;
  64. }
  65.  
  66. echo = ip_info("Visitor", "address");
Add Comment
Please, Sign In to add comment