blocked() публичный статический Метод

public static blocked ( $verbose = false )
Пример #1
0
 public function testBlockedVerbose()
 {
     $this->mockReferer(null);
     $this->assertEquals('Not blocking because referer header is not set or empty', Blocker::blocked(true), 'Should contain verbose output');
     $this->mockReferer('');
     $this->assertEquals('Not blocking because referer header is not set or empty', Blocker::blocked(true), 'Should contain verbose output');
     $this->mockReferer(self::INVALID_DOMAIN);
     $this->assertEquals('Not blocking because we couldn\'t parse root domain', Blocker::blocked(true), 'Should contain verbose output');
     $this->mockGoodReferer();
     $this->assertContains('Not blocking because referer (', Blocker::blocked(true), 'Should contain verbose output');
     $this->mockBadReferer();
     $this->assertContains('Blocking because referer ', Blocker::blocked(true), 'Should contain verbose output');
 }
Пример #2
0
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing invalid referer : ";
mockReferer('.NotAnUrl?/');
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing good referer    : ";
mockReferer('http://www.google.com/?q=query');
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
echo "Testing bad referer     : ";
$domainlist = \Nabble\SemaltBlocker\Blocker::getBlocklist();
mockReferer($domainlist[array_rand($domainlist)]);
$time_pre = microtime(true);
$i = $c;
while ($i--) {
    \Nabble\SemaltBlocker\Blocker::blocked();
}
echo number_format((microtime(true) - $time_pre) / $c * 1000, 8) . "ms\n";
Пример #3
0
<?php

$BLOCKLIST = __DIR__ . DIRECTORY_SEPARATOR . 'blocked';
copy(__DIR__ . DIRECTORY_SEPARATOR . './../domains/blocked', $BLOCKLIST);
chmod($BLOCKLIST, 0777);
include 'semaltblocker.php';
$_SERVER["HTTP_REFERER"] = 'http://semalt.com';
try {
    // Test blocking
    $expected = 'Blocking because referral domain (semalt.com) is found on blocklist';
    $actual = \Nabble\SemaltBlocker\Blocker::blocked(true);
    if (!@assert($expected === $actual)) {
        throw new Exception('Blocking domains failed');
    }
    // Test updating
    file_put_contents($BLOCKLIST, '');
    \Nabble\SemaltBlocker\Updater::update(true);
    $expected = \Nabble\SemaltBlocker\Updater::getNewDomainList();
    $actual = file_get_contents($BLOCKLIST);
    if (!@assert($expected === $actual)) {
        throw new Exception('Updating domains failed');
    }
} catch (Exception $e) {
    echo $e->getMessage() . '<br/>' . PHP_EOL;
}
echo 'All tests finished' . PHP_EOL;
unlink($BLOCKLIST);
Пример #4
0
<?php

require '../vendor/autoload.php';
if (\Nabble\SemaltBlocker\Blocker::blocked()) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' 403 Forbidden');
}
?>
<html>
    <head>
        <title>semalt blocker test target</title>
    </head>
    <body>
        <?php 
echo \Nabble\SemaltBlocker\Blocker::blocked(true);
?>

    </body>
</html>