Although I've got several projects on the go at any one time, I tend to get halfway through one and drop it for a while, only to pick it back up again 6 months later. (Much like progress on this website!)

So, if it looks like I haven't updated this page for a while.. I probably haven't :)

Current project list:

Can you think of something I should be doing? Email me!

PHP "last updated" page

This one took a while to figure out since its my first real crack at using PHP. (Almost all PHP code on my website was thoughtfully created by my alter-geek, Mark Pulford).

For pages which need to use a lot of php code, its best to use an "include" which is added to your html at on the fly.

e.g a typical HTML page calling the function "myfunction" within the file "myextrabits.inc" might look like this:

<? PHP

require "myextrabits.inc";

?>
<HTML>
<HEAD>
<TITLE>My php-html page</TITLE>
</HEAD>
<BODY>

Around this text is <?php myfunction(); ?> code from the included file

</BODY>
</HTML>

 

 

 

 

 

 



The actual file "myextrabits.inc" might look something like this:

<?PHP

function myfunction(){

do something here;

}
?>

 

 

 

 

So for my "last updated code", the html looked like this:

<? PHP

require "lastupdated.inc";

?>
<HTML>
<HEAD>
<TITLE>The Internet made me do it</TITLE>
</HEAD>
<BODY>

My weblog is in here somewhere, then

<?PHP getlastupdated(); ?>
</BODY>
</HTML>

 

 

 

 

 

 

 

and the file that actually does the work looks like this:

<?php

function getlastupdated() {

// sets up the array of pages to keep track of
$MyVar = array("eyecandy.php", "projects.php", "art.php", "20q.php", "links.php", "index.php");

// writes out the common elements of the table
echo "<table width='200' border='1' bordercolor='#000000' cellspacing='0' cellpadding='0'>\n";
echo "<tr>\n";

echo "<td colspan='2'><center>\n";
echo "<font size='4' face='Arial, Helvetica, sans-serif'>\n";
echo "Last updated..</center></font>\n";
echo "</td>\n";
echo "</tr>\n";

// for each file in the array, print out its name
foreach ($MyVar as $value) {

// get the last modified date
$modified = stat($value);

// format the last modified date to something nicer to look at
$modi = date("d.m.y",$modified[10]);

// write out the date value next to the file name
echo "<tr>\n";
echo "<td>\n";
echo "<font size='2' face='Arial, Helvetica, sans-serif'>$value</font>\n";
echo "</td>\n";

//check if the file date is 01.01.70 then this is a generic date meaning its not there
if ($modi == '01.01.70') { //file is not there, must be default time or something?
echo "<td>\n";

// write out a message saying its not there
echo "<div align='right'><font size='2' face='Arial, Helvetica, sans-serif'>\n";
echo "Not up yet</font></div>\n";
echo "</td>\n";

// check if the modified date equals today
} elseif ($modi == date("d.m.y")) {

// if it is, make the font green and write out a message
echo "<TD>\n";
echo "<div align='right'><b><font size='2' face='Arial, Helvetica, sans-serif' color='#336600'>\n";
echo "Today</font></b></div>\n";
echo "</td>\n";

// elsewise the file is there, but not modified today so just write out as normal
} else {
echo "<td>\n";
echo "<div align='right'><font size='2' face='Arial, Helvetica, sans-serif'>\n";
echo "$modi</font></div>\n";
echo "</td>\n";
}

// end the row of the table
echo "</tr>\n";
}
// close the table
echo "</table>\n";
}
?>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If it looks like I comment excessively, its because I did... this is because this page is really here to refresh my ailing memory!

If that code looks like gobbldigook to you for reasons other than my bad coding, you might want to check out php.net , zend.com or phpbuilder.com for some fairly comprehensive documentation.