Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function get_continent_by_ip($ip = false) {
- $code = false;
- if (!$ip) {
- $client = @$_SERVER['HTTP_CLIENT_IP'];
- $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
- $remote = @$_SERVER['REMOTE_ADDR'];
- if (filter_var($client, FILTER_VALIDATE_IP)) {
- $ip = $client;
- } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
- $ip = $forward;
- } else {
- $ip = $remote;
- }
- }
- $response = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip={$ip}"));
- if ($response && isset($response->geoplugin_continentCode)) {
- $code = $response->geoplugin_continentCode;
- }
- return $code;
- }
- //$detectedip = $_SERVER['REMOTE_ADDR'];
- //get_continent_by_ip($detectedip);
- get_continent_by_ip('8.8.8.8');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment