Documentation

RateLimit
in package

Rate-limiting system, to prefent people form doing hacky stuff

Table of Contents

Methods

checkLimitIP()  : bool
Check that a given event has only been hit by the request ip address an allowable number of times
getHitCount()  : int
Return the number of hits matching given conditions for a given time period
logHitFailure()  : mixed
Log a failure hit against the rate-limit system (e.g. password incorrect)
logHitSuccess()  : mixed
Log a successful hit against the rate-limit system (e.g. user was logged in)
logHit()  : mixed
Log a hit against the rate-limit system

Methods

checkLimitIP()

Check that a given event has only been hit by the request ip address an allowable number of times

public static checkLimitIP(string $event, bool|null $success, int $limit, int $time) : bool
Parameters
$event : string

Event to check

$success : bool|null

TRUE to check only successes, FALSE only failures, NULL all events

$limit : int

Maximum number of events

$time : int

Time to search, in seconds

Return values
bool —

TRUE if under the limit, FALSE if over the limit

getHitCount()

Return the number of hits matching given conditions for a given time period

public static getHitCount(array<string|int, mixed> $conditions, int $time) : int
Parameters
$conditions : array<string|int, mixed>

Conditions to match, e.g. 'event', 'success', 'username', 'ip_address' fields

$time : int

Time to check in seconds, e.g. 3600 for one hour

Return values
int —

Number of hits

logHitFailure()

Log a failure hit against the rate-limit system (e.g. password incorrect)

public static logHitFailure(string $event[, string $username = '' ]) : mixed
Parameters
$event : string

The event being done by the user, e.g. 'user-auth-action' or 'form-submit-action'

$username : string = ''

The user who performed the event, may be an empty string for unauthenticated events

logHitSuccess()

Log a successful hit against the rate-limit system (e.g. user was logged in)

public static logHitSuccess(string $event[, string $username = '' ]) : mixed
Parameters
$event : string

The event being done by the user, e.g. 'user-auth-action' or 'form-submit-action'

$username : string = ''

The user who performed the event, may be an empty string for unauthenticated events

logHit()

Log a hit against the rate-limit system

protected static logHit(string $event, bool $success, string $username) : mixed
Parameters
$event : string

The event being done by the user, e.g. 'user-auth-action' or 'form-submit-action'

$success : bool

The status of the event, true for success, false for failure

$username : string

The user who performed the event

On this page

Search results