u214 Posted June 28, 2011 Share Posted June 28, 2011 Hey guys. Ok, let's say I have this query: "SELECT * FROM playerbans WHERE BannedName = 'something' OR BannedIP = '192.168.0.1'" How can I make the "BannedIP" be detected all or just part of it? Lets say, "192.168.0" Will still detect that field? Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/ Share on other sites More sharing options...
Maq Posted June 28, 2011 Share Posted June 28, 2011 How are you storing your IPs? If you have them as INET_ATON and INET_NTOA types, then you can simply condition for a specific range of IPs. Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/#findComment-1235964 Share on other sites More sharing options...
Pikachu2000 Posted June 28, 2011 Share Posted June 28, 2011 I've only run cursory tests on this, and you'll need to be at least somewhat familiar with subnet masks and bitwise operations to understand what it's doing, but here goes. $mask = '255.255.255.0'; $address = '192.168.0.1'; $query = "SELECT * FROM playerbans WHERE BannedName = 'something' OR ( INET_ATON('$mask') & INET_ATON(BannedIP) ) = ( INET_ATON('$mask') & INET_ATON('$address') )"; Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/#findComment-1235971 Share on other sites More sharing options...
u214 Posted June 28, 2011 Author Share Posted June 28, 2011 I appreciate both answers and the code posted. Not exactly what I'm looking for. I should've explained my problem more in detail. Let's say I have this rows: (BannedName)(IP) (Reason) (Date) (Admin) bash1tro. 192.168.0.111 No Reason Give June 28, 2011 - 19:41:49 Admin bash1troo. 192.168 No Reason Given June 28, 2011 - 19:45:08 Admin bash1tro.. 192.168.0.112 No Reason Given June 28, 2011 - 19:45:09 Admin -- As you can see the similarities. The player is still joining the server. Is there a syntax like "strfind" but on that query? Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/#findComment-1236041 Share on other sites More sharing options...
QuickOldCar Posted June 29, 2011 Share Posted June 29, 2011 Lets just say you do make a query with finding ip's starting with 192.168 (first 2 positions), don't you think you'll not be allowing too many people in that entire ip range? Even then sadly if they have a dynamic ip they can always come back, or change their static through their isp. If this person is that much a pain, just block them via htaccess and that range for a while, until he forgets about you. as an example Deny 69.60.114.0 - 69.60.114.255 Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/#findComment-1236128 Share on other sites More sharing options...
fenway Posted July 2, 2011 Share Posted July 2, 2011 Then you're not storing IPs correctly. Quote Link to comment https://forums.phpfreaks.com/topic/240637-selecting-part-or-all-of-an-item/#findComment-1237726 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.