Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // MaxMind Setup
- require_once 'vendor/autoload.php';
- use GeoIp2DatabaseReader;
- $db =new Reader('GeoLite2-City.mmdb');
- $client_ip=$db->city($_SERVER['REMOTE_ADDR']);
- $client_country=$client_ip->country->isoCode;
- // Specification of allowed_countries
- $allowed_countries=array("US","CA");
- // Blocking Logic
- if(!in_array($client_country,$allowed_countries)) {
- header("HTTP/1.0 403 Forbidden");
- echo "<h1>Access Forbidden!</h1>";
- echo "<p>You are accessing from $client_country which is forbidden.</p>";
- exit();
- }
- ?>
- <html>
- <head>
- <title>Example Success</title>
- </head>
- <body>
- <h1>Welcome</h1>
- <p>You have access to this website.</p>
- </body>
- </html>
Add Comment
Please, Sign In to add comment