APIs

  • setDriver
  • setComponent
  • setProperty
  • setProperties
  • setChannel
  • setCaptcha
  • setFilters
  • setIp
  • outputJsSnippet
  • captchaResponse
  • setView
  • createDatabase
  • ban
  • unban
  • limitSession
  • run

The public APIs can be chaining yet SetDriver must be the first and run must be the last.

Chainable

setDriver

  • param DriverProvider
  • return self
$dbLocation = APPPATH . 'cache/shieldon.sqlite3';
$pdoInstance = new \PDO('sqlite:' . $dbLocation);
$shieldon->setDriver(new \Shieldon\Driver\SqliteDriver($pdoInstance));

setComponent

  • param ComponentInterface
  • return self
$shieldon->setComponent(new \Shieldon\Component\Ip());

setProperty

  • param string $key
  • param mixed $value
  • return self
$shieldon->setProperty('time_unit_quota', [
    's' => 4,
    'm' => 20, 
    'h' => 60, 
    'd' => 240
]);

Default settings:

key type value
time_unit_quota array ['s' => 2, 'm' => 10, 'h' => 30, 'd' => 60]
time_reset_limit integer 3600
interval_check_referer integer 5
interval_check_session integer 30
limit_unusual_behavior array ['cookie' => 5, 'session' => 5, 'referer' => 10]
cookie_name string "ssjd"
cookie_domain string "
cookie_value string "1"

setChannel

  • param string $channel Channel name.
  • return self
$shieldon->setChannel('web_project');

// Start new shieldon each day.
$shieldon->setChannel('web_project_' . date('Ymd'));

setCaptcha

  • param CaptchaInterface
  • return self

For deatiled usages, please see Captcha sestion.

$shieldon->setCaptcha(new \Shieldon\Captcha\Recaptcha([
    'key' => '6LfkOaUUAAAAAH-AlTz3hRQ25SK8kZKb2hDRSwz9',
    'secret' => '6LfkOaUUAAAAAJddZ6k-1j4hZC1rOqYZ9gLm0WQh',
    'version' => 'v2',
    'lang' => 'en',
]));

setFilters

  • param array $settings Filter settings.
  • return self
$shieldon->setFilters([
    'session' => true,
    'cookie' => true,
    'referer' => true,
    'frequency' => true,
]);

Default settings:

key type value description
session boolean true Check PHP session cookie.
cookie boolean false Check cookie generated by JavaScript.
referer boolean true Check HTTP_REFERER
frequency boolean true Check time_unit_quota setting.

The Cookie filter is false by default, because you have to output the JavaScript snippet to your web pages. The JavaScript snippet created by outputJsSnippet will generate cookie by JavaScript.

Check out outputJsSnippet for usage.

setIp

  • param string $ip
  • return self
// Here is an example, cature real vistor IP from CloudFlare.
$realIp = $_SERVER['HTTP_CF_CONNECTING_IP'];

// If you use a CDN serive on your website, 
// make sure to cature the real vistor IP, overwise users will get banned.
$shieldon->setIp($realIp);

createDatabase

  • param bool $option true or false [default: true]
  • return self
$this->createDatabase(false);

setView

  • param string $html HTML text string.
  • param string $type The page type.
  • return self
$htmlText = '<html>...bala...{{captcha}} ...bala...</html>';
$this->setView($htmlText, 'stop');

$type

type description
stop The page displayed when user get temporaily banned.
limit The page displayed when user is reached the online session limit.
deny The page displayed when user is in blacklist.
  • Template tag
    • {{captcha}}: The CAPTCHA form for stop page. (required)
    • {{online_info}}: The online session infomation for for limit page.
    • {{lineup_info}}: The line-up number infomation for for limit page.

ban

  • param string $ip Single IP address.
  • return self
$shieldon->ban('33.125.12.87');

unban

  • param string $ip Single IP address.
  • return self
$shieldon->unban('33.125.12.87');

limitSession

  • param integer $amount Maximum amount of online vistors.
  • param integer $period Period. (Unit: second)
  • return self
$shieldon->setSession(500, 300);

Non-chainable

outputJsSnippet

  • return string [The JavaScript string.]

Required if cookie filiter is enabled.

// Output this variable in your page template.
$jsCode = $shieldon->outputJsSnippet();

captchaResponse

  • return boolean

true: Captcha is solved successfully, false overwise.

$result = $this->captchaResponsse();

run

  • return integer

Reponse code:

constant value reason
RESPONSE_DENY 0 Banned permanently.
RESPONSE_ALLOW 1 Passed.
RESPONSE_TEMPORARILY_DENY 2 Banned temporarily.
RESPONSE_LIMIT 3 Stopped due to reaching online session limit.
$result = $shieldon->run();

results matching ""

    No results matching ""