PHP code example of stero / shield

1. Go to this page and download the library: Download stero/shield 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/ */

    

stero / shield example snippets




declare(strict_types=1);

use Stero\Shield\Engine;
use Stero\Shield\EngineConfig;
use Stero\Shield\Events\JsonLinesSink;
use Stero\Shield\Http\RequestFactory;
use Stero\Shield\Rules\Phase;
use Stero\Shield\Rules\SensitivePathRule;
use Stero\Shield\Store\ArrayStore;

ion = $engine->inspect($request, Phase::Inline);
if ($decision->blocked) {
    http_response_code($decision->responseStatus ?? 404);
    echo 'Not Found';
    exit;
}

// Replace this response with your application's request handler.
header('X-Shield-Would-Block: ' . ($decision->wouldBlock ? '1' : '0'));
echo 'hello';
if (function_exists('fastcgi_finish_request')) {
    fastcgi_finish_request();
}
$engine->inspect($request, Phase::Deferred);

new EngineConfig(mode: Mode::Enforce)

use Stero\Shield\Redis\NullStore;
use Stero\Shield\Redis\PhpRedisClient;
use Stero\Shield\Redis\RedisConnector;
use Stero\Shield\Redis\RedisStore;

$connection = RedisConnector::connect(
    getenv('REDIS_HOST') ?: '127.0.0.1',
    (int) (getenv('REDIS_PORT') ?: 6379),
    getenv('REDIS_PASSWORD') ?: null,
);
$store = $connection === null
    ? new NullStore()
    : new RedisStore(new PhpRedisClient($connection), 'my-app:shield:');
sh
php artisan shield:logs
php artisan shield:logs --per-page=20 --severity=high
php artisan shield:logs --group
php artisan shield:logs --json