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 ..