1. Go to this page and download the library: Download survos/bad-bot-bundle 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/ */
survos / bad-bot-bundle example snippets
$ip = $cache->get('banned_ips_' . $ip), function (ItemCache) {
// set the timeout
}
In BeforeRequestListener:
Check the banned IP list (either via the cache)
use Survos\BadBotBundle\Validator\Constraints\IsNotBlacklisted;
//...
/**
* 'baz' type isn't defined in bundle, so it will be handled with
* default_type class. Default one has no validation and will compare
* any value with other existed
*
* @IsNotBlacklisted(type="baz", caseSensetive=true)
* @var string
*/
private $bar;
/**
* 'email' type will dissallow to put invalid emails in blacklist
*
* @IsNotBlacklisted(type="email", caseSensetive=true)
* @var string
*/
private $email;
use LSBProject\BlacklistBundle\Type\TypeInterface;
use LSBProject\BlacklistBundle\Type\DefaultType;
class EmailType extends DefaultType implements TypeInterface
{
/**
* {@inheritDoc}
*/
public function satisfies(string $value): bool
{
return filter_var($value, FILTER_VALIDATE_EMAIL);
}
/**
* {@inheritDoc}
*/
public function supports(string $type): bool
{
return $type === 'email';
}
}
class DefaultType implements TypeInterface
{
//...
/**
* {@inheritDoc}
*/
public function validate(
string $value,
Constraint $constraint,
ExecutionContextInterface &$context,
BlacklistManagerInterface $manager
): void {
if ($manager->isBlacklisted($value, $constraint->type, $constraint->caseSensetive)) {
$context->buildViolation($constraint->message)->addViolation();
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.