Get time zone by request ip

    0

    1

    jvit
    JVIT PHP

    This code will get the time zone from a request from an IP address.

    Shortcut: date.timezone

    /**
    * Get time zone by request ip
    *
    */
    function getTimeZoneUser()
    {
      $json   = file_get_contents('http://ip-api.com/json');
      $timezone = '';
      if (!empty($json)) {
        $ipData = json_decode($json, true);
        if (!empty($ipData['timezone'])) {
          $timezone = $ipData['timezone'];
        }
      }
      return $timezone;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.