Download the PHP package dynamiccarrots/laravel-ip2location without Composer
On this page you can find all versions of the php package dynamiccarrots/laravel-ip2location. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dynamiccarrots/laravel-ip2location
More information about dynamiccarrots/laravel-ip2location
Files in dynamiccarrots/laravel-ip2location
Package laravel-ip2location
Short Description Use the free Ip2Location LITE database within Laravel
License
Informations about the package laravel-ip2location
Laravel-Ip2Location
Ip2Location provides a free non-intrusive database to help you identify your visitors geographical location.
The data you receive from a users IP Address will depend on what database size you download from Ip2Location. The largest of these consists of Country, Region, City, Latitude, Longitude, Zipcode and Timezone.
Only download the database that you need, the large databases can have over 4 million rows. The smallest one has about 160K rows.
As this package uses the LITE/free version of Ip2Location you are not guaranteed 100% accuracy.
Installation
Download Ip2Location Database
Visit this page and download one of the DB files as a CSV, these range from DB1 to DB11. http://lite.ip2location.com/
You will need to create a folder in the database directory called "ip2location" and store the CSV in here with the name "ip2location.csv".
You should have the following structure.
Migrations
Create a new migration file in laravel by running the following command.
Copy the following migration in to the newly created migration file.
Run the migration.
Create update command
Due to the fact IP address ranges get moved around from ISP to ISP all the time. We need to update our database on a monthly basis if you want to stay up to date.
We need to have a command that will allow us to change the ip2location.csv file and use its data to refresh our database.
Run the following command.
This will create a new file in app/Console/Commands called RefreshIp2Location.php.
Replace the code in this new file with this.
Register the new command in /app/Console/Kernel.php by adding RefreshIp2Location::class to the $commands array, this will allow us to run this from the CLI.
Populate the database
Now we have a database set up with the correct table and the csv file stored in the right directory we can run the command to populate the database with the ip2location data.
Run this command.
Use Examples
Return the Country Code of a IP address
Provide your own IP Address and Ip2Location will convert this to a Country Code.
Return the Country Code client
Return the Country Code of the client