You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
2.9 KiB

<?php namespace App\Libraries;
/*******************************************************************************************************************
* Location Class
*
* @return mixed
*
* @author Rick Hays
* @date 2019-11-16
*
* @description
* Takes a JSON encoded string from (https://ip-api.io/api/json)
* This site returns several bit of location data from client.
* Class creates Array of data, and using the Class getter to access the data.
*
* NOTE: YOU HAVE TO HAVE A API TO USE THIS CLASS
* The API Key is free for 12,000 queries per month at time of writing.
*
* Place a file in the same location as this Class File and call it
* (location_api_key.php) and in the file place this bit of code:
*
* <?php
* CONST LOCATION_API_KEY = 'Your API Key';
*
* Get your API at: https://ip-api.io/
*
* @example
* $Location = new Location();
* echo $Location->Data['time_zone'];
* echo ($Location->Data['suspiciousFactors']['isSuspicious'] === TRUE) ? 'TRUE' : 'FALSE';
*
*
*
* -=[ AVAILABLE FIELDS TO CALL ]=-
* 'ip' => string '127.000.000.001'
* 'country_code' => string 'US'
* 'country_name' => string 'United States'
* 'is_in_european_union' => boolean false
* 'region_name' => string 'STATE'
* 'region_code' => string 'ST'
* 'city' => string 'City'
* 'zip_code' => string '00000'
* 'time_zone' => string 'America/Chicago'
* 'latitude' => float 00.0000
* 'longitude' => float -00.0000
* 'metro_code' => int 000
* 'organisation' => string 'Fiber'
* 'flagUrl' => string 'https://ip-api.io/images/flags/us.svg'
* 'emojiFlag' => string '🇺🇸' *** USED ABOVE for SVG NAME ***
* 'currencySymbol' => string '$'
* 'currency' => string 'USD,USN,USS'
* 'callingCode' => string '1'
* 'countryCapital' => string 'Washington D.C.'
* 'suspiciousFactors' =>
* 'isProxy' => boolean false
* 'isTorNode' => boolean false
* 'isSpam' => boolean false
* 'isSuspicious' => boolean false
*
*******************************************************************************************************************
* Revisions:
* YYYY-MM-DD XXX Description
*
******************************************************************************************************************/
require_once 'location_api_key.php';
class Location
{
private $Data;
public function __construct()
{
$this->Data = json_decode(file_get_contents('https://ip-api.io/api/json?api_key=LOCATION_API_KEY'), TRUE);
}
public function __get($item)
{
if(property_exists($this, $item))
{
return $this->$item;
}
}
}