Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************************************************/
- /* Description: This snippet is provide simple way to help user display Visitor's Sunrise and Sunset Time. */
- /* suggestions for different city locations across the country. */
- /* There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at: */
- /*https://www.ip2location.com/tutorials/display-sunrise-sunset-time-using-php-and-bin-database */
- /****************************************************************************************************************/
- /* You can obtain free IP2Location LITE database for bin at https://lite.ip2location.com/ */
- /* You can obtain free IP2Location PHP class module data for at https://www.ip2location.com/developers/php */
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- set_time_limit(0);
- require_once('IP2Location.php');
- // Standard lookup with no cache
- $loc = new \IP2Location\Database('./databases/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-SAMPLE.BIN', \IP2Location\Database::FILE_IO);
- /*
- Cache whole database into system memory and share among other scripts & websites
- WARNING: Please make sure your system have sufficient RAM to enable this feature
- */
- //$loc = new \IP2Location\Database('./databases/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-SAMPLE.BIN', \IP2Location\Database::SHARED_MEMORY);
- /*
- Cache the database into memory to accelerate lookup speed
- WARNING: Please make sure your system have sufficient RAM to enable this feature
- */
- //$loc = new \IP2Location\Database(ROOT . './databases/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
- $ip = $_SERVER['REMOTE_ADDR'];
- //Retrieving data from database
- $time_zone = $loc->lookup($ip, \IP2Location\Database::TIME_ZONE);
- $country_code = $loc->lookup($ip, \IP2Location\Database::COUNTRY_CODE);
- $latitude = $loc->lookup($ip, \IP2Location\Database::LATITUDE);
- $longitude = $loc->lookup($ip, \IP2Location\Database::LONGITUDE);
- //Setting Sun's zenith value
- $zenith = 90+50/60;
- $offset = explode(':', $time_zone);
- date_default_timezone_set("UTC");
- $date = date_create("UTC");
- $sunset = date_sunset(date_timestamp_get($date), SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $offset[0]);
- $sunrise = date_sunrise(date_timestamp_get($date), SUNFUNCS_RET_STRING, $latitude, $longitude, $zenith, $offset[0]);
- //Displaying output
- echo 'Country Code: ' . $country_code . '<br />';
- echo 'Sunset Time: ' . $sunset . '<br />';
- echo 'Sunrise Time: ' . $sunrise . '<br />';
- echo 'Latitude: ' . $latitude . '<br />';
- echo 'Longitude: ' . $longitude . '<br />';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement