Guest User

Untitled

a guest
May 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. // MaxMind Setup
  4. require_once 'vendor/autoload.php';
  5. use GeoIp2DatabaseReader;
  6.  
  7. $db =new Reader('GeoLite2-City.mmdb');
  8. $client_ip=$db->city($_SERVER['REMOTE_ADDR']);
  9. $client_country=$client_ip->country->isoCode;
  10.  
  11. // Specification of allowed_countries
  12. $allowed_countries=array("US","CA");
  13.  
  14. // Blocking Logic
  15. if(!in_array($client_country,$allowed_countries)) {
  16. header("HTTP/1.0 403 Forbidden");
  17. echo "<h1>Access Forbidden!</h1>";
  18. echo "<p>You are accessing from $client_country which is forbidden.</p>";
  19. exit();
  20. }
  21. ?>
  22.  
  23. <html>
  24. <head>
  25. <title>Example Success</title>
  26. </head>
  27. <body>
  28. <h1>Welcome</h1>
  29. <p>You have access to this website.</p>
  30. </body>
  31. </html>
Add Comment
Please, Sign In to add comment