ip

ไปเจอ database ว่า ip นั้นขอประเทศไหนก็เลยจดไว้

http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

ก็ import ลง db ซะ ข้อมูลข้างในจะเป็น range ของ ip นั้นเริ่มและสุดที่ไหน
วิธีการก็เอา ip ของเราไป convert dot address to network address (inet_aton) ก่อน
หลักการคือ ถ้า
ip = a.b.c.d
ก็จะเป็น
(a*256*256*256) + (b*256*256) + (c*256) + d;

หรือใช้ function INET_ATON ของ MySQL ก็มีอยู่แล้ว

ปล. รูปธงประเทศเอาจาก famfamfam ก็ได้
เพราะชื่อไฟล์เขารันตาม ISO 3166-1 alpha-2 country codes

Recent comments

Add to Technorati Favorites