git-svn-id: https://msi/svn/firstRepo/Service/branches/Slim3@40 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
class CheckFromMW
|
||||
{
|
||||
/**
|
||||
* Example middleware invokable class
|
||||
*
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
|
||||
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
|
||||
* @param callable $next Next middleware
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$currentRefererRequest = $request->getHost();
|
||||
$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))
|
||||
{
|
||||
return $response->withStatus(500)->write('Generic error occurred');
|
||||
}
|
||||
*/
|
||||
$currentHostRequest = $app->request()->getHost();
|
||||
if(!in_array($currentHostRequest, $allowedHost))
|
||||
{
|
||||
return $response->withStatus(403)->write('Request arrive from host not allowed');
|
||||
}
|
||||
|
||||
return $next($request, $response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user