Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- function get_client_ip ()
- {
- // Nothing to do without any reliable information
- if (!isset ($_SERVER['REMOTE_ADDR'])) {
- return NULL;
- }
- // Header that is used by the trusted proxy to refer to
- // the original IP
- $proxy_header = "HTTP_X_FORWARDED_FOR";
- // Get the IP address of the client behind trusted proxy
- if (array_key_exists ($proxy_header, $_SERVER)) {
- // Header can contain multiple IP-s of proxies that are passed through.
- // Only the IP added by the last proxy (last IP in the list) can be trusted.
- $client_ip = trim (end (explode (",", $_SERVER[$proxy_header])));
- // Validate just in case
- if (filter_var ($client_ip, FILTER_VALIDATE_IP)) {
- return $client_ip;
- } else {
- // Validation failed - beat the guy who configured the proxy or
- // the guy who created the trusted proxy list?
- // TODO: some error handling to notify about the need of punishment
- }
- }
- // In all other cases, REMOTE_ADDR is the ONLY IP we can trust.
- return $_SERVER['REMOTE_ADDR'];
- }
- $ip = get_client_ip(); // the IP address to query
- $query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
- if($query && $query['status'] == 'success') {
- $curr_uri = check_plain(request_uri());
- if ($query['country'] == "United Kingdom" && $curr_uri == "/"){
- header("Location: uk-homepage");
- }
- }
- function ukredirect_init(){
- get_client_ip();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement