Advertisement
karol3883

Untitled

Mar 7th, 2023
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2.  
  3. const BLOCKED_COUNTRIES = [
  4.     'russia',
  5.     'indonesia',
  6.     'china',
  7.     'poland',
  8. ];
  9.  
  10. const REDIRECT_URL = 'https://firmamaja.com/404.htm';
  11.  
  12. header('Content-Type: application/json');
  13.  
  14. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? null;
  15.  
  16. if (null === $ip) {
  17.     echo json_encode([
  18.        'success' => false,
  19.     ]);
  20.     exit;
  21. }
  22.  
  23. $query = @unserialize(file_get_contents("http://ip-api.com/php/$ip"));
  24.  
  25. if (empty($query) || empty($query['status']) || $query['status'] !== 'success') {
  26.     echo json_encode([
  27.         'success' => false,
  28.     ]);
  29.     exit;
  30. }
  31.  
  32. echo json_encode([
  33.     'success' => in_array(strtolower($query['country']), BLOCKED_COUNTRIES),
  34.     'redirect_url' => REDIRECT_URL,
  35. ]);
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement