It is necessary on the server side (in PHP) to set the country (and city) of the user, so that depending on this to display this or that content.
Found a resource ( http://ipgeobase.ru:7020/geo?ip= ) and judging by the description of a good, updated. Nowhere did I find how to work with it correctly and whether it can be applied in my case. All I need is to substitute the IP address of the incoming User into this URL and then retrieve the data that is in this resource as XML.
I have prescribed such a script:
function get_city_by_ip($ip) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://ipgeobase.ru:7020/geo?ip='.$ip); curl_setopt($ch, CURLOPT_HEADER, false); $data = curl_exec($ch); $city = ( !curl_errno($ch) && $xml = simplexml_load_string($data) ) ? $xml->ip->city : false; curl_close($ch); return $city; } var_dump( get_city_by_ip( $_SERVER['REMOTE_ADDR'] ) ); But I don’t get any content from this resource. I get
bool(false) What am I doing wrong or forgot to register? Perhaps there are other ways to tutor the user's country, but I need such external sources where I could send the curl and get the data, install an additional database and the libraries in my case are not an option.
