PHP code example of cloakings / cloakings-common

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

    

cloakings / cloakings-common example snippets


use Cloakings\CloakingsCommon\CloakerFactory;
use Cloakings\CloakingsCommon\CloakModeEnum;
use Cloakings\CloakingsCommon\SampleCloaker;

$cloaker = new SampleCloaker();
// or
$cloaker = (new CloakerFactory())->create(SampleCloaker::class);

$result = $cloaker->handle(new Request(server: ['HTTP_USER_AGENT' => 'Chrome 100']));
// $result->mode === CloakModeEnum::Real
// show real site

$result = $cloaker->handle(new Request(server: ['HTTP_USER_AGENT' => 'GoogleBot', 'REMOTE_ADDR' => '8.8.8.8']));
// $result->mode === CloakModeEnum::Fake
// show fake site

$result = $cloaker->handle(new Request(server: ['HTTP_USER_AGENT' => 'GoogleBot', 'REMOTE_ADDR' => '11.22.33.44']));
// $result->mode === CloakModeEnum::Response
// stop and show this response

$result = $cloaker->handle(new Request()); // no user agent
// $result->mode === CloakModeEnum::Error
// decide by yourself: may be show default (fake or real) site, may be try chaining decision to another cloaker

use Cloakings\CloakingsCommon\AlwaysRealCloaker;
use Cloakings\CloakingsCommon\CloakerFactory;
use Cloakings\CloakingsCommon\SampleCloaker;

$cloaker = (new CloakerFactory())->createChain([
    AlwaysRealCloaker::class,
    SampleCloaker::class,
]);