How to calculate by IP the city and continent of the user who came to the site and record the data in date_default_timezone_set('Континент/Его город') ?

  • What will you do if you find the continent of the EU and the city of Novo-Aleksandrovka? What timezone will you set? It’s better, of course, as @romeo advises, to ask the client for the time / timezone, unnoticed by his client to send ajax to the server and store / process there. - Boris
  • @LiveStreet, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina
  • @boris_U, if the task is reduced to displaying the correct time, then an ajax request is nowhere. DateTime :: W3C is a format with a time difference Ymd\TH:i:sP , i.e. for Moscow: 2015-03-02T03: 52: 35 + 03: 00. Knowing this, the same momentjs will adjust the time itself according to the client’s system time. In addition, the datetime attribute for the time tag will also help search engines. - romeo

2 answers 2

If you need to display the date in accordance with the time zone of the user, then usually do it on the client. Look towards the momentjs . In addition, out of the box will be available to change time in real time. You could see a similar technique in VK, github, ... On the server in this case, you can set UTC + 0, or any other timezone and output the date in DateTime:: W3C format. The datetime attribute of the time tag is needed for this.

To search for geo-data by ip on the server side, you can use the following tools .

    You can install libapache2-mod-geoip - then GEOIP_ADDR, GEOIP_CONTINENT_CODE, GEOIP_COUNTRY_CODE, GEOIP_CITY will appear in $ _SERVER

    http://dev.maxmind.com/geoip/legacy/mod_geoip2/

    You can install the extension php5-geoip, but there may be problems with certain versions of libgeoip and php itself - https://bugs.php.net/bug.php?id=64692