Created
March 31, 2017 19:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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