Created
November 4, 2015 20:47
-
-
Save elliotforbes/d44f1bab0cff8dd40eac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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