Jump to content

Recommended Posts

Hello,

 

On a previous thread, thanks to Barand, I have something to say when the sunrise and sunset for an area will be based upon the longitude and latitude.

 

Just in case I knocked out a simplified version with out datetime that covers day and night conditions. Should get you started.

 

<?php
$lat = 52;
$long= -2;


// $timenow = time();							 // live version

$hour = isset($_GET['hour']) ? $_GET['hour'] : 0;
$timenow = mktime($hour,0,0);					 // testing version

$today = mktime(0,0,0);
$todayInfo = date_sun_info($today, $lat, $long);
$nighttime = false;

switch(true) {
case $timenow < $todayInfo['sunrise']: // is it pre-sunrise
 // get last night's sunset
 $nighttime = true;
 $yesterdayInfo = date_sun_info(strtotime('-1 days', $today), $lat, $long);
 $percent = round(($timenow - $yesterdayInfo['sunset'] )*100/($todayInfo['sunrise'] - $yesterdayInfo['sunset']));
 break;

case $timenow > $todayInfo['sunset']:
 // get tomorrow's sunrise
 $nighttime = true;
 $tomorrowInfo = date_sun_info(strtotime('+1 days', $today), $lat, $long);
 $percent = round(($timenow - $todayInfo['sunset'] )*100/($tomorrowInfo['sunrise'] - $todayInfo['sunset']));
 break;

default:
 $percent = round(($timenow - $todayInfo['sunrise'])*100/($todayInfo['sunset'] - $todayInfo['sunrise']));
 break;
}
if ($nighttime) {
$bg = '#000';
$fg = '#FFF';
} else {
$bg = '#FFF';
$fg = '#000';
}

echo "<div style='width:50px; height:30px; text-align:center; border: 1px solid black; background-color:$bg; color:$fg; padding-top:5px; margin-bottom: 30px;'>";
echo "$percent%</div><hr>";

printf ("Today, sunrise is %s, sunset is %s",
 date('g:ia', $todayInfo['sunrise']),
 date('g:ia', $todayInfo['sunset']));
?>
<form>
Hour <input type="text" name="hour" value="<?php echo $hour?>" size="5">
<input type="submit" name="btnSubmit" value="Test">
</form>

 

I would like to make this unique for each user using GeoIP location.

 

http://dev.maxmind.com/geoip/geolite

 

I would like to start off by using the free version, however I do not know where to begin, I don't know which download I need for the co-ordinates and country/city and I do not know how to install it on the 1and1 myadmin PHP or echo anything onto the page.

 

I know I've not said much, however I hardly know anything about this and don't even know where to begin as I can't find any tutorials or videos to help me get something set up.

 

Best Regards,

Tim

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.