PHP code example of kriosa-ai / kriosa-php

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

    

kriosa-ai / kriosa-php example snippets




$kriosa = new Kriosa('sk_your_api_key');
$kriosa->protect();

kriosa_protect('sk_your_api_key');

// In app/Http/Middleware/KriosaMiddleware.php


namespace App\Http\Middleware;

use Closure;
use Kriosa;

class KriosaMiddleware
{
    public function handle($request, Closure $next)
    {
        $kriosa = new Kriosa(config('services.kriosa.key'));
        $kriosa->protect();
        
        return $next($request);
    }
}

// In app/Http/Kernel.php
protected $routeMiddleware = [
    // ...
    'kriosa' => \App\Http\Middleware\KriosaMiddleware::class,
];

Route::middleware(['kriosa'])->group(function () {
    Route::post('/upload', [UploadController::class, 'store']);
});

// At the top of your index.php or bootstrap file
->protect();

// Your application code continues here...

$kriosa = new Kriosa('sk_your_api_key', [
    'timeout'        => 5,           // API timeout in seconds
    'debug'          => false,       // Enable debug logging
    'fail_closed'    => false,       // Block requests if API unreachable
    'show_badge'     => true,        // Show "Protected by Kriosa" badge
    'badge_position' => 'bottom-right', // Badge position
    'trusted_ips'    => [],          // Array of IPs to always allow
    'blocked_ips'    => [],          // Array of IPs to always block
    'rate_limit'     => 100,         // Requests per minute
]);

// For authenticated routes (recommended)
$kriosa = new Kriosa('sk_your_key', [
    'fail_closed'  => true,
    'timeout'      => 5,
    'debug'        => false
]);

// For public routes
$kriosa = new Kriosa('sk_your_key', [
    'fail_closed'  => false,
    'timeout'      => 3,
    'debug'        => false
]);

// Laravel example
$kriosa = new Kriosa(config('services.kriosa.key'), [
    'fail_closed' => app()->environment('production') ? true : false,
    'timeout'     => app()->environment('production') ? 5 : 10,
    'debug'       => app()->environment('local'),
]);
bash
composer