Skip to content

Instantly share code, notes, and snippets.

@firefoxrebo
Created March 31, 2017 19:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firefoxrebo/6b3da10d166abc8d5abab2db1dc47cdb to your computer and use it in GitHub Desktop.
Save firefoxrebo/6b3da10d166abc8d5abab2db1dc47cdb to your computer and use it in GitHub Desktop.
A simple php class that retreives user's geo location data using a free api
<?php
class GeoData
{
public $id;
public $propertyId;
public $ipaddress;
public $created;
public $returnVisit;
public $userAgentString;
public $country;
public $countryCode;
public $city;
public $region;
public $regionName;
public $lon;
public $lat;
public static function getVisitInformation ()
{
$url = 'http://ip-api.com/json/' . $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment