Tracking location info by ip address.
Next, run the Composer command to install the latest stable version:
composer require munna/iplocation
to create a class instance
// Use this as namespace
use Munna\IpLocation\IpLocation;
// Set Your Ip Address
$ip = "YOUR_IP_ADDRESS";
//this is optional. Find this api key by visiting https://ipinfo.io/account/home?service=google&loginState=create
$api_key = "API_TOKEN";
//If you have this api_key
$location = new IpLocation($ip, $api_key);
// If you do not have this api_key pass only ip
$location = new IpLocation($ip);
// Finally init the class
$location->init();
After init class instance. You will be get the all of these data.
// Get Ip Address
$ip = $location->ip;
//full info as an array
$info = $location->info();
// get region name
$region = $location->region;
// get country
$country = $location->country;
// get city name If you set api_key when create instance
$cityName = $location->city;
// get ioc name
$loc = $location->loc;
// get postal
$postal = $location->postal;
// get flag url
$flag = $location->flag;
// get timeZone
$timeZone = $location->timeZone;
{
"ip": "27.147.201.241",
"hostname": "dhknat-27.147.201.241.link3.net",
"city": "Dhaka",
"country": "BD",
"region": "Dhaka",
"loc": "23.7104,90.4074",
"postal": "1000",
"org": "AS23688 Link3 Technologies Ltd.",
"flag": "https://raw.githubusercontent.com/MunnaAhmed/Flags/main/bd.png"
}
This package is open-sources and licensed under the MIT license.
Thank you very much. Please give a star.