Judge the city based on the Sina IP database

Source: Internet
Author: User
Based on the Sina IP database, the city PHP determines the visitor city based on the Sina IP database and matches the city set in the database field.
For example, if the visitor city is Beijing, if the current visitor city = city with ID 1 in the matched database, the output result a is not equal to the output result AB.
Databases such
----------------------------------------------------
Id city info

1 Beijing, Shanghai, Shenzhen, and other 1-tier cities
2 Nanjing, Wuhan, and other 2-tier cities
----------------------------------------------------------

What should I do? is it reasonable for me to set table 1 to 2 to classify cities.
I want to block the specified region, set the first-tier or second-tier cities in the background, and output different results based on the user's City matching database.
Thanks for the specific PHP code ....


Reply to discussion (solution)

So?

$ Query = mysql_query ("select id from table where city like '% Beijing %'") or die (mysql_error (); $ thread = mysql_fetch_assoc ($ query ); $ id = isset ($ thread ['id'])? $ Thread ['id']: 0; if ($ id> 0) {// indicates matching echo 'A';} else {echo 'AB ';}

So?

$ Query = mysql_query ("select id from table where city like '% Beijing %'") or die (mysql_error (); $ thread = mysql_fetch_assoc ($ query ); $ id = isset ($ thread ['id'])? $ Thread ['id']: 0; if ($ id> 0) {// indicates matching echo 'A';} else {echo 'AB ';}




Table
------------------------
Id name open
1 Zhang San 0
2 Li Si 1
-------------------
To set an IP city shielding table, for example, set table a id to 1. the blocked area to Line 1, Line 2, or the specified city.
How to Design Table B (IP city shielding table)

What is the open field.
Table
------------------------
Id name open
1 Zhang San 0
2 Li Si 1
-------------------

Table city design is as follows:
Id city info group

1 Beijing 1st line city 1
2 Shanghai 1st line city 1
3 Shenzhen 1st line city 1
4 Nanjing line 2 City 2
5 Wuhan 2-line city 2
----------------------------------------------------------

Ip city shielding table
Id, uid, city_id city_group
1 1 0 1
2 2 0 1
3 1 0 2
4 1 12 0

Uid indicates the id of Table a, city_id indicates the city table id, and city_group indicates the number of cities.
The ip city shielding table records the first-tier and second-tier cities and cities with city_id = 12.

Query the cities blocked by John.
Select * from ip where uid = 1; find the group and city_id sets

Then select * from city where group not in ($ group) and city_id not in ($ city_id );

First point .. you need to have the data of the province and city corresponding to each IP address... then find the corresponding city based on the obtained IP address... jump to the URL of the corresponding city... however, scripts are usually used for detection... will not be detected in the program ..

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.