I am looking for a better way to allow certain domains access to my laravel application. I am currently using Laravel 5.1 and using Middleware to redirect if the referenced domain is not in the white list domains.
class Whitelist {
public function handle($request, Closure $next)
{
$referer = Request::server('HTTP_REFERER');
$host = parse_url($referer, PHP_URL_HOST);
$host = str_replace("www.", "", $host);
$whiteList = Cache::remember('whitelist_domains', 1400, function(){
$query = WhiteListDomains::lists('domain')->all();
return $query;
});
if(in_array($host, $whiteList)){
return $next($request);
}else{
header('HTTP/1.0 403 Forbidden');
die('You are not allowed to access this file.');
}
}
}
Is there a better way to do this, or am I on the right track?
Any help would be appreciated.
Thanks.
source
share