After that you will download a 30MB ZIP file. Then you need to run this command to download that library:Ĭomposer install -prefer-source IP Database Setupįirst thing you need to do is to visit IP2Location LITE DB11 page, click "Download IPv4 BIN" and then register for a free download account. The file above tells to the composer that PHP implementation for ip2location library should be downloaded and made available to our app. If you are not familiar with composer, it is a dependencies manager that takes responsibility to download all the libraries your application needs. Then, as your are in the 'ip2loc' folder, create a file called "composer.json" with this contents: Here we will place the binary file of the database. Also create a sub-folder inside called 'db'. We need to create a new folder in your local Web server document root, for example, 'ip2loc'. But there were a couple issues with it, so read carefully to overcome the obstacles. The installation process is described here. In this article we will see how to build an app even without a database, we will access a IP database in the form of a binary file which might be handy on many hosting environments.Īlthough the IP2Location full database version is paid, you can download a free version that is still very useful. There are several ways to interact with IP database: you could grab a CSV file of the IPs and geo-data, or import it in the database and run SQL queries. It is very simple to do, so let's see the details. Facebook became suspicious and asked me to confirm my password.Īs you can see, this technique is used in any modern project. For example, once I flew from Ukraine to Denmark, and Facebook did not like that I accessed my account in the morning in one country, and a few hours later I got to Facebook from another distant country in the evening. If you visit Gmail from home in your own country, and you can see there is someone who accessed your account using your username and password from another country far-far away, then it is possible that your account has been hacked. Second, country detection helps to improve the safety and security of the users. Once your country is detected, the Web site will automatically switch to your local language and your local currency. It helps to search for cheap airline tickets. Users like it when a site is made convenient, and it is not necessary to dig in the page in order to find the language switcher when it exists.Īlso your application can show the prices based on the user's local currency. If a visitor is from England, it makes sense to switch the language to English. When you know the country of the user, you can, for example, switch the user interface messages to their language. adapt the site depending on the user location, thus making them more happy and loyal. Why is it important?įirstly, it helps to build better localization for the Web site guests, i.e. IP geolocation detection is used in many projects for instance to detect from which country a user has come from. Why Would You Need to Detect the User Location from the IP Address? Contents Why Would You Need to Detect the User Location from the IP Address? Installation IP Database Setup Code Example Testing Conclusion
0 Comments
Leave a Reply. |