Jump to content

Ban by IP


conker87

Recommended Posts

I'm looking to use PHP to ban IP addresses rather than use .htaccess. I'm wondering what the best way to go about this is? Should I store these IP address in a file or create a little admin UI for myself to add addresses into a database.

 

That said, how would I compare the $_SERVER['HTTP_HOST'] to the fetched array?

 

Thanks guys.

Link to comment
https://forums.phpfreaks.com/topic/103721-ban-by-ip/
Share on other sites

If you put the ip addresses in a database (which you should anyway because you will end up with hundreds or thousands of banned addresses depending on how bad someone wants to visit your site or hot link your content), one per row, you can simply search using a query -

 

SELECT * FROM your_table WHERE ip_column = '$_SERVER['REMOTE_ADDR']'

 

Short answer, let the database do the work. (The fetch_array code you just posted would only work if you add a column for each IP and that would be a terrible table design.)

Link to comment
https://forums.phpfreaks.com/topic/103721-ban-by-ip/#findComment-531059
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.