MrTIMarshall Posted February 20, 2013 Share Posted February 20, 2013 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 Link to comment https://forums.phpfreaks.com/topic/274738-setting-up-database-and-echoing-data-onto-page/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.