Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
/**
|
|
3 |
* This file is part of the Shieldon package.
|
|
4 |
*
|
|
5 |
* (c) Terry L. <contact@terryl.in>
|
|
6 |
*
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
8 |
* file that was distributed with this source code.
|
|
9 |
*
|
|
10 |
* php version 7.1.0
|
|
11 |
*
|
|
12 |
* @category Web-security
|
|
13 |
* @package Shieldon
|
|
14 |
* @author Terry Lin <contact@terryl.in>
|
|
15 |
* @copyright 2019 terrylinooo
|
|
16 |
* @license https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
|
|
17 |
* @link https://github.com/terrylinooo/shieldon
|
|
18 |
* @see https://shieldon.io
|
|
19 |
*/
|
|
20 |
|
|
21 |
declare(strict_types=1); |
|
22 |
|
|
23 |
namespace Shieldon\Firewall\Captcha; |
|
24 |
|
|
25 |
use Shieldon\Firewall\Captcha\CaptchaProvider; |
|
26 |
|
|
27 |
/**
|
|
28 |
* Add form fields for the CSRF features of some frameworks.
|
|
29 |
*/
|
|
30 |
class Csrf extends CaptchaProvider |
|
31 |
{
|
|
32 |
/**
|
|
33 |
* Form input name.
|
|
34 |
*
|
|
35 |
* @var string
|
|
36 |
*/
|
|
37 |
protected $name = ''; |
|
38 |
|
|
39 |
/**
|
|
40 |
* Form input value.
|
|
41 |
*
|
|
42 |
* @var string
|
|
43 |
*/
|
|
44 |
protected $value = ''; |
|
45 |
|
|
46 |
/**
|
|
47 |
* Constructor.
|
|
48 |
*
|
|
49 |
* It will implement default configuration settings here.
|
|
50 |
*
|
|
51 |
* @param array $config The field of the CSRF configuration.
|
|
52 |
*
|
|
53 |
* @return void
|
|
54 |
*/
|
|
55 | 3 |
public function __construct(array $config = []) |
56 |
{
|
|
57 | 3 |
parent::__construct(); |
58 |
|
|
59 | 3 |
foreach ($config as $k => $v) { |
60 | 3 |
if (isset($this->{$k})) { |
61 | 3 |
$this->{$k} = $v; |
62 |
}
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Response the result.
|
|
68 |
*
|
|
69 |
* @return bool
|
|
70 |
*/
|
|
71 | 3 |
public function response(): bool |
72 |
{
|
|
73 | 3 |
return true; |
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Output a required HTML.
|
|
78 |
*
|
|
79 |
* @return string
|
|
80 |
*/
|
|
81 | 3 |
public function form(): string |
82 |
{
|
|
83 | 3 |
$html = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '">'; |
84 |
|
|
85 | 3 |
return $html; |
86 |
}
|
|
87 |
}
|
Read our documentation on viewing source code .