Use GeoIP and PHP to build a simple MySQL geographic database

Source: Internet
Author: User
Tags geoip

MaxMind GeoIP is a very useful tool used to identify the country where your Web site visitors are located. But once you have the geographic information, what should you do? A common application of such data is the advertisement for geographic location. The basic steps for using GeoIP data are quite simple-you read the visitor's remote IP address (using GeoIP ing database) to map this address into a country code, the Country Code is then used to display ads designed for the country. List A is a php sample script that displays these steps. This script assumes that you have a MySQL database that contains a list of advertisement entries and is indexed according to the country code. Once the customer's IP address is obtained through the special $ REMOTE_ADDR variable, the IP address can be mapped to the country code. Then we use the country code to randomly select an advertisement for the country from the advertisement bar list. Pay special attention to the SQL query -- it first Retrieves all records that match the country code (advertisement bar), and the country needs to be returned by the geoip_country_code_by_addr () method, then, randomly select one from each advertisement bar. (Selected) the corresponding file name of the AD bar will be dynamically inserted into the HTML page. If you want to, you can use this unique ad ID to further combine the ad and click tracking scripts to determine whether your advertising system is successful or not. Other use of geographic data targeted advertising is one of the most common applications of geographic databases. However, you can also use this information to precisely provide other types of content for (different) Users: weather forecasts, securities information, news headlines, and so on. You can also use this data in other ways. For example, you can redirect users to content written in their local language and restrict/grant them access permissions based on their location, or automatically adjust the display of the shopping cart to use the local currency. I will leave you the right to discover this technological innovation application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.