Cless Posted November 1, 2007 Share Posted November 1, 2007 Hello. I need help creating an IP Banning system. I know how to do all of the coding, except, what would be the data stored? You would store the first few numbers in the IP Address into the database? If so, which ones, and if not, could someone please explain? Basically, in the Administrator Panel, I would create a page that you enter the IP Address of the person you wish to ban, use the substr_replace function to cut off the unneeded parts of the IP Address (if you use exact addresses, it won't work). Afterwards, I enter it into an MySQL Table. Then, on an include file that I add in every file, or something, I search the database. I check if the IP Address is in the database. To select the data, would I use... $IP= $_SERVER['REMOTE_ADDR']; $IP= substr_replace($IP, "", 3); mysql_query("SELECT * FROM IPBanned WHERE IP LIKE '$IP%'"); What I want to know is, what would the query be, and in substr_replace, at which number would I remove all the rest of the variable? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75681-solved-ip-banning/ Share on other sites More sharing options...
pocobueno1388 Posted November 1, 2007 Share Posted November 1, 2007 Why do you want to remove any part of the ip address? You need the whole thing. You also shouldn't use LIKE in your query, because you want the exact IP. So change that to mysql_query("SELECT * FROM IPBanned WHERE IP = '$IP'"); Quote Link to comment https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382958 Share on other sites More sharing options...
Cless Posted November 1, 2007 Author Share Posted November 1, 2007 The issue is, IP Addresses change a lot. Quote Link to comment https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382959 Share on other sites More sharing options...
PHP_PhREEEk Posted November 1, 2007 Share Posted November 1, 2007 If you are going to use LIKE in your query, you wouldn't need to do any sub-string functions at all. Just put the IP in the database, and query with LIKE. That's what LIKE does... it's sort of a sub-string search for DB records. IP in DB = 216.72.36.77 IP coming into your server is 216.72.36.81 Query says: WHERE 'ip' = '216.72.36.77' - IP is not banned WHERE 'ip' LIKE '216.72.36.%' - IP range 216.72.36.00 - 216.72.36.255 is banned (therefore this IP would be banned) WHERE 'ip' LIKE '216.72.3%' - etc... each LIKE clause that is more vague will end up banning larger and larger ranges. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382964 Share on other sites More sharing options...
Cless Posted November 1, 2007 Author Share Posted November 1, 2007 Oh, I get it! Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.