PHP code example of supergnaw / form-security
1. Go to this page and download the library: Download supergnaw/form-security library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
supergnaw / form-security example snippets
$exampleToken = FormSecurity::token_generate('example');
if (FormSecurity::token_verify("token_name")) {
echo "security token is valid!";
} else {
echo "security token is invalid!";
}
FormSecurity::token_clear_all();
$input = [
"var1" => 1,
"var2" => 2,
"var3" => 3
];
$whitelist = ["var1", "var2"];
$output = FilterSecurity::apply_whitelist($whitelist, $input);
// $output = [1, 2]
$blacklist = ["var1", "var3"];
$output = FilterSecurity::apply_blacklist($blacklist, $input);
// $output = [2]
$filter = [
"foo" => "int",
"bar" => "string",
];
$_GET = [
"foo" => "1",
"bar" => "2"
]
$get = FormSecurity::filter_input(input: "get", types: $filter);
// $get = ["2"]
$_POST = [
"foo" => 1,
"bar" => 2
];
$post = FormSecurity::filter_input(input: "post", types: $filter);
// $post = [1]
$input = "Hell0 w0rld!";
$output = FormSecurity::clean_to_alpha($input);
// $output = "Hellwrld"
$input = "Hell0 w0rld!";
$output = FormSecurity::clean_to_alnum($input);
// $output = "Hell0w0rld"
html
<form>
<input type="hidden" name="token_name" value=" echo $exampleToken;