Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/75681-solved-ip-banning/
Share on other sites

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'");

 

Link to comment
https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382958
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/75681-solved-ip-banning/#findComment-382964
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.