According to the Sina IP database, judge the city

Source: Internet
Author: User
PHP based on the Sina IP database, to determine the city of visitors, matching the database set in the field of the city
For example, to determine the city of visitors to Beijing, matching database if the current visitor city =id is 1 of the urban field output result a if not equal to the output of the result AB
Database such as
----------------------------------------------------
ID City Info

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

How to write, and I set the table 1 line City 2 line city classification is reasonable.
I want to block the designated area, background set 1-line city or 2-line city, according to the user city matching database, output different results.
Ask for specific PHP code thanks ....


Reply to discussion (solution)

Such

$query = mysql_query ("Select ID from table where city like '% Beijing") or Die (Mysql_error ()); $thread = Mysql_fetch_assoc ($qu ery); $id = Isset ($thread [' id '])? $thread [' id ']: 0;if ($id >0) {//= Find match    echo ' a ';} else{    Echo ' AB ';}

Such

$query = mysql_query ("Select ID from table where city like '% Beijing") or Die (Mysql_error ()); $thread = Mysql_fetch_assoc ($qu ery); $id = Isset ($thread [' id '])? $thread [' id ']: 0;if ($id >0) {//= Find match    echo ' a ';} else{    Echo ' AB ';}




Table A
------------------------
ID Name Open
1 Sheets 30
2 Li 41
-------------- -----
Want to set up an IP City shield table, such as set Table a ID 1 shielded area for 1 line city, or 2 line, or designated city
So how to design table B (IP City shield table)

What does the open field do?
Table A
------------------------
ID Name Open
1 Sheets 30
2 Li 41
-------------- -----

Table city is designed as follows
ID City Info Group

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

IP City Shield table
ID, uid, city_id City_group
1 1 0 1
2 2 0 1
3 1 0 2
4 1 12 0

The UID is the ID of table A, and city_id is the city table Id,city_group represents several line cities
The IP City shielding table record means that Zhang Sanxi and second-tier cities and city_id=12 cities, Li Shishi cover the first-tier cities.

Query the city of Zhang Sanxi.
SELECT * from IP where uid=1; Find group and CITY_ID collections

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

1th.. You have to have each IP corresponding to the province city data ... Then according to obtain the IP to find the corresponding city ... Go to the URL of the corresponding city ... However, the script is usually used to detect ... Will not be detected inside 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.