how to check if ip is in ip range
I can't figure this. Can this be done alone with mysql, or there are somethings I need to do with php script.Let say I have many ip range stored in the database one of them is, 22.214.171.124 - 126.96.36.199. The table structure is like this
Let say someone accessed a website and his ip is 188.8.131.52. Now with this ip, it should get name1 from customer name column as it's is in the range of 184.108.40.206 - 220.127.116.11.
ip customer name
18.104.22.168 - 22.214.171.124 name1
126.96.36.199 - 188.8.131.52 name2
I would store the upper and lower bounds as two integer fields, using MySQL's conversion functions (or PHP's ip2long()) to convert them. Then you can similarly convert any IP address of interest to an integer, and use the SQL "BETWEEN" operator to see if there is a match.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)