Calculate Sunrise and Sunset Value from IP Address

Language

The example demonstrate you on how to calculate the sunrise and sunset value from IP address, or to be specific - the geolocation from IP address, without the use of weather library. This solution requires a geolocation table, such as the DB11.LITE database which can be downloaded free from lite.ip2location.com. I would like to keep the source code zip small, so, please download it from http://lite.ip2location.com. Note: the database here refers to the IP2Location BIN format, in which all geolocation data contains inside a single BIN file for accessing that free you from database setup. The code is pretty straight-forward and easy to be understood. A complete copy (without the database) has been included in the zip file for your download. In summary, this solution will extract the timezone value from the IP address, the visitor's IP address, and perform the calculation using PHP library and return the sunrise and sunset information. Before running the sample code, please make sure all files are saved into the same folder.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byAnonymous (not verified)on Mon, 12/09/2013 - 20:47

When I try to run it on my local computer, it says: Fatal error: Class 'PEAR_Exception' not found in D:\wamp\www\temp\sunrise_sunset\IP2Location.php on line 102. How to fix this error?

Add new comment