F
F
fisherspoons2016-03-25 10:19:41
WordPress
fisherspoons, 2016-03-25 10:19:41

Wordpress location plugin?

Perhaps someone has come across or knows, you need a plugin to display an international location (city), but not in the form of Google maps, but in the form of a string

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Kozlov, 2016-03-25
@trampick

I use 2 functions in my geolocation projects.
get_ip() - returns the client's ip,
get_region() - returns the region by the given ip. You can redo it to give out the city.
$xml = simplexml_load_file(' ipgeobase.ru:7020/geo?ip= ' . $ip);
this line we get all the information about the client by ip.
You can also get the city through the $xml object

function get_ip() {
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

function get_region($ip = '', $to = 'utf-8') {
    $ip = ($ip) ? $ip : $_SERVER['REMOTE_ADDR'];
    $xml = simplexml_load_file('http://ipgeobase.ru:7020/geo?ip=' . $ip);
    //print_R($xml);
    if ($xml->ip->message) {
        if ($to == 'utf-8') {
            return $xml->ip->message;
        } else {
            if (function_exists('iconv'))
                return iconv("UTF-8", $to . "//IGNORE", $xml->ip->message);
            else
                return "The library iconv is not supported by your server";
        }
    } else {
        if ($to == 'utf-8') {
            if (!empty($xml->ip->region))
                return $xml->ip->region;
            else
                return $xml->ip->country;
        } else {
            if (function_exists('iconv'))
                return iconv("UTF-8", $to . "//IGNORE", $xml->ip->region);
            else
                return "The library iconv is not supported by your server";
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question