Determining the city that visited the site

Is there a way to determine which city a person came to the site from? (Well, put the result into a variable in php, say, $user_gorod.)


Answer 1, authority 100%

function get_city_quest($ip) {
    $data = '<ipquery><fields><all/></fields><ip-list><ip>' . $ip . '</ip></ip-list></ipquery>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://194.85.91.253:8090/geo/geo.html");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $xml = curl_exec($ch);
    curl_close($ch);
    if ( substr_count($xml, 'Not found') )
        return false;
    $city = substr(substr($xml, strpos($xml, '<city>'), strpos(substr($xml, strpos($xml, '<city>')), '</city>')), 6);
    return iconv('Windows-1251', 'UTF-8', $city);
}

Level yourself.


Answer 2, authority 50%

GeoIP will help you, one thing is bad, that normal bases are paid, but if you search…

Leave a reply

Please enter your comment!
Please enter your name here