Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?
  2.  
  3. function get_client_ip ()
  4. {
  5. // Nothing to do without any reliable information
  6. if (!isset ($_SERVER['REMOTE_ADDR'])) {
  7. return NULL;
  8. }
  9.  
  10. // Header that is used by the trusted proxy to refer to
  11. // the original IP
  12. $proxy_header = "HTTP_X_FORWARDED_FOR";
  13.  
  14. // Get the IP address of the client behind trusted proxy
  15. if (array_key_exists ($proxy_header, $_SERVER)) {
  16.  
  17. // Header can contain multiple IP-s of proxies that are passed through.
  18. // Only the IP added by the last proxy (last IP in the list) can be trusted.
  19. $client_ip = trim (end (explode (",", $_SERVER[$proxy_header])));
  20.  
  21. // Validate just in case
  22. if (filter_var ($client_ip, FILTER_VALIDATE_IP)) {
  23. return $client_ip;
  24. } else {
  25. // Validation failed - beat the guy who configured the proxy or
  26. // the guy who created the trusted proxy list?
  27. // TODO: some error handling to notify about the need of punishment
  28. }
  29. }
  30.  
  31.  
  32. // In all other cases, REMOTE_ADDR is the ONLY IP we can trust.
  33. return $_SERVER['REMOTE_ADDR'];
  34. }
  35.  
  36. $ip = get_client_ip(); // the IP address to query
  37. $query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
  38. if($query && $query['status'] == 'success') {
  39.  
  40. $curr_uri = check_plain(request_uri());
  41. if ($query['country'] == "United Kingdom" && $curr_uri == "/"){
  42. header("Location: uk-homepage");
  43. }
  44. }
  45.  
  46.  
  47. function ukredirect_init(){
  48. get_client_ip();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement