1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<?php
namespace Riimu\Kit\CSRF\Source;
/**
* Looks for the token in the $_POST global array variable.
* @author Riikka Kalliomäki <riikka.kalliomaki@gmail.com>
* @copyright Copyright (c) 2014, Riikka Kalliomäki
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class PostSource implements TokenSource
{
/** @var string Name of the input field for the CSRF token */
private $fieldName;
/**
* Creates a new instance of PostSource.
* @param string $fieldName Name of the input field in $_POST
*/
public function __construct($fieldName = 'csrf_token')
{
$this->fieldName = $fieldName;
}
public function getRequestToken()
{
if (!isset($_POST[$this->fieldName])) {
return false;
}
return $_POST[$this->fieldName];
}
}