Skip to content

Instantly share code, notes, and snippets.

@elliotforbes
Created November 4, 2015 20:47
Show Gist options
  • Save elliotforbes/d44f1bab0cff8dd40eac to your computer and use it in GitHub Desktop.
Save elliotforbes/d44f1bab0cff8dd40eac to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
class AdMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Test to see if the requesters have an ip address.
if($request->ip() == null){
throw new \Exception("IP ADDRESS NOT SET");
}
$country=file_get_contents('http://api.hostip.info/get_html.php?ip=' . $request->ip());
echo $country;
if(strpos($country, "UNITED STATES")){
throw new \Exception("NOT FOR YOUR EYES, NSA");
} else {
return redirect("index");
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment