Q:

adding PHP code to magento and calling it in phtml

So I'm trying to add a few lines of custom PHP code to a site that I am using Magento with. I have some understanding that I would need to create a module and the necessary files and directories but every thing I've has either resulted in a broken page or my result just not showing up at all. I want to be able to create the code as well as maybe call to it in the phtml file I want it to show on, how can I do this? Also here is the code I want to put in:
 <?php
$h = date('G'); //set variable $h to the hour of the day
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.

if ($h < 7) $img = 'fish.jpg';
else if ($h < 20) $img = 'frogs.jpg';
else $img = 'potatoes.jpg';

//if it's before 7am, use fish image
//if not and it's before 8pm, use frogs
//otherwise, potatoes
?>

A:

So copy this code to your .phtml file. Make sure to edit the path to your image files.
<?php
  $h =date('G');
  if($h < 7) {
    $img = '/path/to/your/fish.jpg';
  } else if($h < 20) {
    $img = '/path/to/your/frog.jpg'
  } else {
    $img = '/path/to/your/potatoes.jpg'
  }
?>

<div class='server-date'> <img src='<?php echo $img ?>'/> </div> 

Remind the image will only change when the user refresh the page because php is a server side language.

