/**
* Checks for a form token in the request.
*
* Use in conjunction with HTMLHelper::_('form.token') or Session::getFormToken.
*
* @param string $method The request method in which to look for the token key.
* @param boolean $redirect Whether to implicitly redirect user to the referrer page on failure or simply return false.
*
* @return boolean True if found and valid, otherwise return false or redirect to referrer page.
*
* @since 3.7.0
* @see Session::checkToken()
*/
public function checkToken($method = 'post', $redirect = true)
{
$valid = Session::checkToken($method);
if (!$valid && $redirect) {
$referrer = $this->input->server->getString('HTTP_REFERER');
if (!Uri::isInternal($referrer)) {
$referrer = 'index.php';
}
$this->app->enqueueMessage(Text::_('JINVALID_TOKEN_NOTICE'), 'warning');
$this->app->redirect($referrer);
}
return $valid;
}