FormToken
in package
The Form Token class
This class is limit the use of form data to only one shot.
Tags
Table of Contents
Constants
- ERROR_INVALID_TOKEN = 'invalidFormToken'
- HTML_PREFIX = 'token_'
- SESSION_KEY = 'FORM_TOKENS'
Properties
- $DEFAULT_TOKEN_LIMIT : int
- The default max token
- $TOKEN_LENGTH : int
- The default token length
- $lastToken : string
- Last token
- $maxUsage : int
- Max allowed usage of one token
- $name : string
- The name
- $tokenLimit : int
- Max allowed token
Methods
- __construct() : mixed
- Constructor
- __toString() : string
- Get HTML input tag as string
- generateToken() : string
- Generate a new token
- generateTokenHTML() : string
- Generate a new token and return HTML input tag
- validate() : bool
- Validate the given token
- validateCurrent() : bool
- Validate token in request
- validateForm() : void
- Validate the given token from form or throw an UserException
Constants
ERROR_INVALID_TOKEN
public
mixed
ERROR_INVALID_TOKEN
= 'invalidFormToken'
HTML_PREFIX
public
mixed
HTML_PREFIX
= 'token_'
SESSION_KEY
public
mixed
SESSION_KEY
= 'FORM_TOKENS'
Properties
$DEFAULT_TOKEN_LIMIT
The default max token
public
static int
$DEFAULT_TOKEN_LIMIT
= 10
Can not be unlimited or refreshed pages will create a non-limited amount of tokens We store the minimum amount of data to allow no control of expiration
$TOKEN_LENGTH
The default token length
public
static int
$TOKEN_LENGTH
= 16
$lastToken
Last token
protected
string
$lastToken
$maxUsage
Max allowed usage of one token
protected
int
$maxUsage
$name
The name
protected
string
$name
$tokenLimit
Max allowed token
protected
int
$tokenLimit
Methods
__construct()
Constructor
public
__construct([string|null $name = null ][, int|null $maxToken = null ][, int $maxUsage = 1 ]) : mixed
Parameters
- $name : string|null = null
- $maxToken : int|null = null
- $maxUsage : int = 1
-
Number of max usage, default value is 1.
__toString()
Get HTML input tag as string
public
__toString() : string
Return values
stringgenerateToken()
Generate a new token
public
generateToken() : string
Return values
string —The token
generateTokenHTML()
Generate a new token and return HTML input tag
public
generateTokenHTML([bool $force = false ]) : string
Parameters
- $force : bool = false
Return values
string —The HTML input tag
validate()
Validate the given token
public
validate(string $token) : bool
Parameters
- $token : string
Return values
bool —True if the token is valid
validateCurrent()
Validate token in request
public
validateCurrent(InputRequest $request) : bool
Parameters
- $request : InputRequest
Return values
boolvalidateForm()
Validate the given token from form or throw an UserException
public
validateForm(InputRequest $request[, string|null $domain = null ]) : void
Parameters
- $request : InputRequest
- $domain : string|null = null