Finally It Works

I think I have finally completed my age progression bar script. I have tested it and it seems to work ok. This is why I’m now allowing you lucky people out there to get your hands on it.

Age Progression Bar
  1<?
  2################################################################################
  3#AGEPROGRESSION BAR          REV. 4.0                          M.Tunstall 2004 #
  4#------------------------------------------------------------------------------#
  5#----------------------http://www.deltanova.co.uk------------------------------#
  6#------------------------------------------------------------------------------#
  7#The idea behind this project is to create a visual indicator to show how long #
  8#you have left before you get a year older.                                    #
  9################################################################################
 10#Revision History                                                              #
 11#------------------------------------------------------------------------------#
 12#REV 4.0 Modified the age calculation as age was reported incorrectly when     #
 13#            birthmonth and current month were the same (2/11/2004)                            #
 14#REV 3.0 Modified the script to output XHTML 1.1 compliant code, now uses      #
 15#        external stylesheet                                                       #
 16#REV 2.0 Rewrote days calculation, fixed bugs, modified output code. (2002)    #
 17#REV 1.0 Basically Working with some bugs.                                     #
 18################################################################################
 19#USE:                                                                          #
 20#           include("APB.php");  // Put where you want on the page                 #
 21# // Place the foloowing in the pages header tags to include the stylesheet    #
 22# <link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />#
 23################################################################################
 24//Fill in your brithday information
 25//If you were born before 1st Jan 1970 this script will not work
 26//This is because its based on a unix timestamp taken from that date to the present
 27//The day you were born [1-31{where appropriate}(no leading zeros)]
 28$Bday = 16;
 29//The month you were born [1-12 (no leading zeros)]
 30$Bmonth = 1;
 31//The year you were born 4-digits (ie 1980)
 32$Byear = 1980;
 33//Your Name (ie John Smith or John)
 34$Name = Bob;
 35################################################################################
 36#####################DONT EDIT BEYOND THIS LINE#################################
 37################################################################################
 38
 39################################################################################
 40# -------------------------getAge Function-------------------------------------#
 41# getAge will accept the following variables                                   #
 42# getAge('September 3rd, 1980');                                               #
 43# getAge('1980-9-3');                                                          #
 44# getAge('1980/09/03');                                                            #
 45################################################################################
 46function getAge($_dob)
 47{
 48    $dob = date("Y-m-d",strtotime($_dob));
 49    $ageparts = explode("-",$dob);
 50
 51    // calculate age
 52    $age = date("Y-m-d")-$dob;
 53
 54    // return their age (or their age minus one year if it's not their birthday yet, in current year
 55    return (date("nd") < $ageparts[1].str_pad($ageparts[2],2,'0',STR_PAD_LEFT)) ? $age-=1 : $age;
 56}
 57#################################################################################
 58#################################################################################
 59#################################################################################
 60
 61//Get details of todays date for calculation purposes
 62$today = getdate();
 63$Tday = $today['mday'];
 64$Tmonth = $today['mon'];
 65$Tyear = $today['year'];
 66// this is today (create date string)
 67$nowdate = mktime(0,0,0,date("m"),date("d"),date("Y"),0);
 68// this is my birthday (create date string)
 69$birthday = mktime(0,0,0,"$Bmonth","$Bday","$Byear",0);
 70// calculate my age in years
 71$age = getAge('1982-11-7');
 72// calculate my next age in years
 73$nextage = $age + 1;
 74// my next birthday (create date string)
 75$nextbirthday = mktime(0,0,0,"$Bmonth","$Bday",date("Y"),0);
 76// if $nextbirtday is in the past, add 1 year to $nextbirthday
 77if ($nextbirthday<$nowdate)
 78{
 79$nextbirthday=$nextbirthday+(60*60*24*365);
 80}
 81// calculate the remaining day's till my next birthday
 82$DaysToGo=intval(($nextbirthday-$nowdate)/(60*60*24));
 83################################################################################
 84#  This next section of code controls the results to be output                 #
 85################################################################################
 86// The output bar is 100px wide and represents 365 days.
 87// Each pixel represents 3.65 days
 88$OnePercent = 3.65;
 89// Width of progres to go
 90 $Width2 = ($DaysToGo/$OnePercent);
 91// Percentage complete
 92 $perc=100-($Width2);
 93// Width of current progress
 94 $Width1 = (100 - $Width2);
 95// Output the calculated percentage to 4 decimal places
 96 $prcnt = substr($perc,0,6);
 97// Change variables to display altered output on Birthday
 98if(($Tday == $Bday) && ($Tmonth == $Bmonth))
 99{
100$DTG = "365";
101$StartGreeting = 'Happy Birthday <div class="APB3">';
102$Person = $Name;
103$EndGreeting = '</div>';
104}
105else
106{
107$DTG = "$DaysToGo";
108$StartGreeting ="";
109$Person ="";
110$EndGreeting ="";
111}
112?>
113<?
114##################################################################################
115# This section of code is for the layout of the output                           #
116##################################################################################
117# If you plan on displaying the output on a single page, you will need to        #
118# uncomment the header and footer code below.                                    #
119# If you are including the code in a page, the headers must not be included.     #
120# Including the headers will cause an invalid page layout. When including you    #
121# will still need to include the stylesheet link in the header tags of the page  #
122# you are putting it on. Below is the stylesheet link                            #
123# <link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />  #
124##################################################################################
125#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
126#<html xmlns="http://www.w3.org/1999/xhtml">
127#<head>
128#<title>Age Progession Bar</title>
129#<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
130#<link rel="stylesheet" type="text/css" media="screen" href="APB_Style.css" />
131#</head>
132#<body>
133?>
134<div class="APB">
135<div class="APB1">Age Progression Bar</div>
136<div class="APB2"> Current Age:<div class="APB3"><? echo "$age"; ?></div></div>
137<div class="APB2" >Days till <? echo "$nextage";?>:<div class="APB3"><? echo "$DTG"; ?></div></div>
138<div class="APB2" >Trasnsition Progress:<div class="APB3"><? echo "$prcnt"; ?> %</div></div>
139<div class="APB45"><div class="APB4"><div class="APB5" style="width:<? echo "$Width2"; ?>px"></div></div></div>
140<div class="APB2" ><? echo "$StartGreeting $Person $EndGreeting"; ?></div>
141<? #echo "$nowdate $birthday $age2"; ?>
142</div>
143<p/>
144<?
145#</body>
146#</html>
147?>
148<?
149################################################################################
150# Thanks to neotek who gave me the code for his "AgeBar" script which                  #
151# inspired me.                                                                 #
152# http://neotek.m0use.net                                                      #
153################################################################################
154?>
Age Progression Bar Stylesheet
 1.APB
 2{
 3        background-color:#f9f9f9;
 4        width:124px;
 5        margin:0px;
 6border:1px solid #bbb;
 7}
 8
 9
10.APB1
11{
12       background-color:#f9f9f9;
13           color:#000;
14           font-size:10px;
15           text-align:center;
16text-decoration:underline;
17           font-family:Arial, Times, serif;
18           padding-top:2px;
19}
20.APB2
21{
22       background-color:#f9f9f9;
23           color:#000;
24           font-size:10px;
25           text-align:center;
26           font-family:Arial, Times, serif;
27}
28.APB3
29{
30       background-color:#f9f9f9;
31           color:#384c7f;
32           font-size:10px;
33           text-align:center;
34           font-family:Arial, Times, serif;
35}
36.APB45
37{
38                background-color:#f9f9f9;
39                text-align:center;
40                padding-bottom:2px;
41
42}
43.APB4
44{
45       background-color:#0066cc;
46           color:#cccccc;
47           font-size:10px;
48           text-align:right;
49           font-family:Arial, Times, serif;
50           width:100px;
51           height:10px;
52           border:solid 1px #fff;
53}
54.APB5
55{
56       background-color:#ccc;
57           color:#ff0045;
58           font-size:10px;
59           text-align:center;
60           font-family:Arial, Times, serif;
61
62           height:10px;
63           float:right;
64}
Previous: Birthday   Next: Phat Sound