| 1 | <?php |
||
| 5 | class CsrfHelper |
||
| 6 | { |
||
| 7 | const TOKEN_NAME = 'csrftoken'; |
||
| 8 | const DEFAULT_TOKEN = '1234'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Get a CSRF token from the given cookie file |
||
| 12 | * |
||
| 13 | * @param string $file |
||
| 14 | * @return string|null |
||
| 15 | */ |
||
| 16 | public static function getTokenFromFile($file) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param string $line |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | protected static function parseLineForToken($line) |
||
| 37 | { |
||
| 38 | if (empty(strstr($line, self::TOKEN_NAME))) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | preg_match('/'.self::TOKEN_NAME.'\s(\w*)/', $line, $matches); |
||
| 43 | if ( ! empty($matches)) { |
||
| 44 | return $matches[1]; |
||
| 45 | } |
||
| 46 | |||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | public static function getDefaultCookie() |
||
| 57 | |||
| 58 | } |
||
| 59 |