Download the PHP package pulkitjalan/ip-geolocation without Composer
On this page you can find all versions of the php package pulkitjalan/ip-geolocation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pulkitjalan/ip-geolocation
More information about pulkitjalan/ip-geolocation
Files in pulkitjalan/ip-geolocation
Package ip-geolocation
Short Description IP Geolocation Wrapper with Laravel Support
License MIT
Homepage https://github.com/pulkitjalan/ip-geolocation
Informations about the package ip-geolocation
IPGeolocation
IP Geolocation Wrapper with Laravel Support
Supported Drivers (Services)
Requirements
- PHP >= 8.1
Installation
Install via composer
Laravel
There is a Laravel service provider and facade available.
Add the following to the providers
array in your config/app.php
Next add the following to the aliases
array in your config/app.php
Next run php artisan vendor:publish --provider="PulkitJalan\IPGeolocation\IPGeolocationServiceProvider" --tag="config"
to publish the config file.
Using an older version of PHP / Laravel?
If you are on a PHP version below 8.1 or a Laravel version below 9.0, use an older version of this package.
Usage
The ipGeolocation class takes a config array as the first parameter or defaults to using the ip-api
driver.
Example:
IP-API
To use the ip-api pro service you can set the options in your config.
Pro Example:
Maxmind Database
To use Maxmind database as the driver you can set the options in your config.
Database Example:
Maxmind Api
To use Maxmind api as the driver you can set the options in your config.
Web API Example:
IPStack
To use the ipstack as the driver set the config.
Example:
Laravel
To use this package in Laravel, simply update the config file in config/ip-geolocation.php
to get the same effect. The driver can be set using the IPGEOLOCATION_DRIVER
env.
Available Methods
IPGeolocation will try to determin the ip using the following http headers: HTTP_CLIENT_IP
, HTTP_X_FORWARDED_FOR
, HTTP_X_FORWARDED
, HTTP_FORWARDED_FOR
, HTTP_FORWARDED
, REMOTE_ADDR
in this order. Optionally use the setIp
method to set it.
There are a number of available methods to pull out the required information. All methods will return an empty string if data is unavailable.
Get latitude
Get longitude
Get city
Get country
Get country code
Get region
Get region code
Get postal code
Get timezone
Get isp (not supported on all drivers)
Get all geo information
Get raw geo information
Update Database
There is an update command available to help with updating and installing a local ip geolocation database. The following will download and install/update the database file to /path/to/database.mmdb
. As of 30th December 2019, Maxmind requires users to create an account and use a license key to download the databases.
Laravel
Once you have registered the service provider (supports auto discovery), you can use the command php artisan ip-geolocation:update
Services
IP-API
IP-API is a free (or paid) service that can also be used instead of the database file or the paid maxmind service. They do have some limitations on the free service so please have a look at the docs first.
Maxmind
You can use the free database from maxmind (license_key required) or their web api service. You can signup and get a free license code here.
All versions of ip-geolocation with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/console Version ^10.0|^11.0
guzzlehttp/guzzle Version ^7.5|^7.8
geoip2/geoip2 Version ^3.0