eTraxx.com
 
 
 
 Websiteology » Version Code
This is the Websiteology : Version Code Page
website version program description Feedback

The Volume ...
First of all, this is just for fun. That having been said then, this may look simple but there are layers here my friend. Hidden layers. The Volume is simply a caculation of how many years the eTraxx.com webiste(s) have been around. I started the first one in 1999 ... soooo ... we do some simple (ok relatively simple) coding in php using the associative array getdate() to get the current year and subtracting 1998 from that (could have subtracted 1999 and added one):
$date_now = getdate();
$Volume = $date_now['year'] - 1998;
... and Version data
The Version is a bit more complicated .. but was fun to code. The number to the left of the decimal point indicates the number of major versions the page has undergone. I just "guess-a-mated" the starting number. For example, I guessed that the version of the home page is about the fifth major iteration while this Websiteology page is the first version. The number to the right of the decimal is incremented by .01 each time I upload a new version of the page to the server. But .. I'm getting ahead of myself here.

First, we set up a path for our data files:
// Path for data files
$Data_File_Path = "** path to data files **";
Find the date of the current file. (The variable $file is determined earlier elsewhere by $file = basename($_SERVER['SCRIPT_NAME']); .. and yes, I could have used $file in the place of $Current_File in the following code, but I wanted to make it clear (to myself) exactly what I was doing here:
// last modification date of current file being iterated.
$Current_File = "$file";
$last_modification_current = filemtime($Current_File);
Get the name of the current data file by replacing the .php extension with .txt
// Derive name of data file from current iterated file.
$Data_File = $Data_File_Path . substr_replace($Current_File, "txt", -3);
Use an If statement to determine if a data file for the current file exists. If it does, then use the file() function to read the data file into an array, then copy the array data into two variables (again, yes $Array[0] is indeed a variable .. but to me, $last_modification_file means more to me:
// Determine if file exists ...
if (file_exists("$Data_File")) {

  // Open data file
  $FileName = "$Data_File";
  $FilePointer = fopen ($FileName, "r");
  $Array = file ($FileName);
  fclose ($FilePointer);

  // read array data into variables
  $last_modification_file = $Array[0];
  $last_version_file = $Array[1];
If the current file date is newer then the one stored in the data file. If it is, then overwrite the date in the data file and increment the version by .01 ... and set the version variable $Version to the current file date:
  // determine if current iterated file mod date is newer then one stored.
  if ($last_modification_current > $last_modification_file) {
    // update data file ..
    $FileName = "$Data_File";
    $FilePointer = fopen ($FileName, "w");
    // update with new modification date
    fwrite ($FilePointer, "$last_modification_current\n");
    // increment the version by .01
    $last_version_current = $last_version_file + .01;
    fwrite ($FilePointer, "$last_version_current");
    fclose ($FilePointer);
    $Version = $last_version_current;
Else, the current file date is the same as that in the data file, then simply assign the version variable $Variable with the date from the file, $last_version_file:
  } else {
    $Version = $last_version_file;
  }
Finally, if the first If statement fails, there isn't a data file for the current file, then it falls through to this Else statement and a data file must be created. The version variable $Version is set to 1 (this is a newbee) and the date and version are written to the file:
} else {
  $Version = "1";
  $FileName = "$Data_File";
  $FilePointer = fopen ($FileName, "w");
  // update with last modification date
  fwrite ($FilePointer, "$last_modification_current\n");
  fwrite ($FilePointer, "$Version");
  fclose ($FilePointer);
}
Final Note: Was there REALLY a need for all of this? Heck no! Like I said at the very first, it was for fun .. and the chance to teach myself some more PHP. I haven't made much effort to compact this code. The reason is that the more compact and tight the code .. the harder (for me) to figure out just "What the heck" I did when I look at the code later on! Reading books on programming, you will often see a statement somewhat like "Make sure you remark your code throughly you may find it difficult to understand just what you did 6 months later ...". Shoot .. I have trouble the next day!

Safe-Harbor Statement: This works here at home .. keeping fingers crossed that it will also do so when I upload it to the server. I also need to implement error handling .. hmmm ..

Any commnents: edtrax@etraxx.com
Comments       Add Comments
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 eTraxx.com
>