Files
IlLievitario-Service/include.php
T

34 lines
1.1 KiB
PHP

<?php
require_once "./config.inc.php";
// inclusione del file contenente la classe
require_once "./MySqlClass.php";
require_once "./utility.php";
require_once 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->hook('slim.before.router', function () use ($app, $allowedHost) {
$currentRefererRequest = $app->request()->getReferer();
$currentRefererRequest = substr($currentRefererRequest, 7); //Senza http://
$indexDoublePoint = strpos($currentRefererRequest, ':');
$indexFirstSlash = strpos($currentRefererRequest, '/');
$currentRefererRequest = substr($currentRefererRequest, 0, $indexDoublePoint > 0 && $indexDoublePoint < $indexFirstSlash ? $indexDoublePoint : $indexFirstSlash );
if(!in_array($currentRefererRequest, $allowedHost))
{
$app->halt(500, "Generic error occurred");
}
$currentHostRequest = $app->request()->getHost();
if(!in_array($currentHostRequest, $allowedHost))
{
$app->halt(403, "Request arrive from host not allowed " . $currentHostRequest );
}
});
?>