How block IP in PHP? |
Hi
I need block ip with PHP not firewall or htaccess I know that i can forbidden user with send status to header Is there other way?
You can create a filter that always redirect to a page with an error message when you detect the IP addresses you want to block:
https://codeigniter4.github.io/userguide...lters.html
@includebeer, he's using CodeIgniter 3.
You can check when they access the site by using CodeIgniter's ip_address() method. Store the blocked IP's in the database load them on startup into an array then get the users ip using ip_address() and loop through the blocked ip array to see if it's in there. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(01-25-2020, 07:00 AM)includebeer Wrote: You can create a filter that always redirect to a page with an error message when you detect the IP addresses you want to block: But i use Codeigniter 3 Codeigniter 4 is hard to learning now ![]() (01-25-2020, 09:00 AM)InsiteFX Wrote: @includebeer, he's using CodeIgniter 3.Yes it is good way but it busy database for many IP
Option 1: Store in database and upon reading them - store them in a cache engine e.g. Redis for X time.
Option 2: Store them in PHP-file. You can use hooks for both options. If you don't want to display any message just terminate it with exit;.
(01-26-2020, 12:30 AM)jreklund Wrote: Option 1: Store in database and upon reading them - store them in a cache engine e.g. Redis for X time. A question? If i add IP to htaccess file Is is working? or need to restart apache?
Your .htaccess will be read on any new request. So you can block new ip-adressers with it.
|
Welcome Guest, Not a member yet? Register Sign In |