IPFilter
    
            
            in package
            
        
    
    
    
        
            Prevents brute force attacks through a list of IP addresses and their counters failed attempts.
Tags
Table of Contents
- BAN_SECONDS = 600
 - The number of seconds the system blocks access.
 - MAX_ATTEMPTS = 5
 - Maximum number of access attempts.
 - $filePath : string
 - Path of the file with the list.
 - $ipList : array<string|int, mixed>
 - Contains IP addresses.
 - __construct() : mixed
 - IPFilter constructor.
 - clear() : void
 - Clean the list of IP addresses and save the data.
 - isBanned() : bool
 - Returns true if attempts to access from the IP address exceed the MAX_ATTEMPTS limit.
 - setAttempt() : void
 - Add or increase the attempt counter of the provided IP address.
 - readFile() : void
 - Reads file and load IP addresses.
 - readIp() : void
 - Load the IP addresses in the ipList array
 - save() : void
 - Stores the list of IP addresses in the file.
 
Constants
BAN_SECONDS
The number of seconds the system blocks access.
    public
        mixed
    BAN_SECONDS
    = 600
    
        
    
MAX_ATTEMPTS
Maximum number of access attempts.
    public
        mixed
    MAX_ATTEMPTS
    = 5
    
        
    
Properties
$filePath
Path of the file with the list.
    private
        string
    $filePath
    
    
    
    
$ipList
Contains IP addresses.
    private
        array<string|int, mixed>
    $ipList
    
    
    
    
Methods
__construct()
IPFilter constructor.
    public
                    __construct() : mixed
    
    
    
        Return values
mixed —clear()
Clean the list of IP addresses and save the data.
    public
                    clear() : void
    
    
    
        Return values
void —isBanned()
Returns true if attempts to access from the IP address exceed the MAX_ATTEMPTS limit.
    public
                    isBanned(string $ip) : bool
    
        Parameters
- $ip : string
 
Return values
bool —setAttempt()
Add or increase the attempt counter of the provided IP address.
    public
                    setAttempt(string $ip) : void
    
        Parameters
- $ip : string
 
Return values
void —readFile()
Reads file and load IP addresses.
    private
                    readFile() : void
    
    
    
        Return values
void —readIp()
Load the IP addresses in the ipList array
    private
                    readIp(array<string|int, mixed> $line) : void
    
        Parameters
- $line : array<string|int, mixed>
 
Return values
void —save()
Stores the list of IP addresses in the file.
    private
                    save() : void