If you liked this article, then please subscribe to our YouTube Channel for video tutorials. If you have more questions about the implementation, you can find more tutorials in IP2Location Blog. You can filter traffic, block or redirect users based on their locations. Once you can see all the geolocation fields returned by the IP2Location DB11 LITE data, you can use them in many scenarios. You should see all the geolocation data for your own IP address. First, retrieve the IP address from the networking protocol or server-side variable of the Web server. $st = $pdo->prepare('select * from `ip2location_db11` where inet_aton(:ip) bindParam(':ip', $ip, PDO::PARAM_STR) Įcho 'country_code: '. This database provides a solution to determine the country, region or state, city, latitude, longitude, and ZIP code of origin for any IP address in a few simple steps. $ip = $_SERVER // web visitor's IP address SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) We will now create the PHP webpage to query the database and output the geolocation data for the page visitor.Ĭreate a page called test.php and paste the following code into it. Part 2: Querying the geolocation data in your PHP web page INFILE '/root/ip2location_data/IP2LOCATION-LITE-DB11.CSV' Now run the following in MySQL to import the data. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin In your MySQL, run the following to create the database and table that we’ll store the DB11 data. Once you’ve downloaded the zipped file, extract out the IP2LOCATION-LITE-DB11.CSV data file to a folder called /root/ip2location_data (this is just an example folder name). The first step is to download the DB11 LITE database file from which is free after sign-up. IP2Location is a C library that enables the user to find the country, region, city, latitude, longitude, zip code, time zone, ISP, domain name, connection type. We’ll assume you are using MySQL as PHP usually operates with MySQL. Let’s assume your website is running an Apache web server with PHP powering the backend. Part 2 will show how to use PHP to query the database and retrieve the results. Part 1 deals with creating the database & table as well as importing the data. We will explore how to implement this geolocation feature into your own website using PHP. Using the IP address of the web visitor, the website operator can target relevant ads, contents or change the language of the website based on your geolocation country. The most common is the showing of ads local to you even though the website may be foreign. Visit any websites and you’ll most likely find some form of localization being used.
0 Comments
Leave a Reply. |