With the help of this simple library, you can get Country, State, City, and many other pieces of information about your users.
This library uses the ip-api.com to retrieve IP location data.
composer require soltivo/location
$options = [
"ip" => "127.0.0.1",
"lang" => "en",
"fields" => [
"isp", "org", "as",
]
];
$location = new \Soltivo\Location\Location($options);
$countryaa2 = $location->countryCode;
$state = $location->stateName;
$city = $location->city;
$options = [
"ip" => "",
"fields" => [],
"lang" => "",
"test" => false
];
The works component can be appended to other resources.
parameter | type | description | required | see |
---|---|---|---|---|
ip | string | IP address of the user. | yes | |
fields | array | Fields to retrieve. | no | Fields List |
lang | string | Language to retrieve data | no | Localization |
test | boolean | Set true to use for testing connection issues | no |
$testing = false;
$lang = "en";
$fields = [
"country",
"countryCode",
"region",
"regionName",
"city",
"zip",
"proxy",
"currency",
"timezone",
"continent",
"continentCode",
"district"
];
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.