The first thing you need to find out is what language the cgi program was written in. When I first started out I thought cgi was a language and discovered that in fact it was the name of a group of languages, or for the use of a group of languages.
cgi includes perl (which is more than just a web language), asp, php, and even java.
So... if your guest book is written in perl and you try to include it in php then it won't run.
Lets assume that they are in different languages. Here are your options
convert your header and footer to that language
get a new guestbook script
use frames so that the header, footer and guestbook are in separate pages, each with their own frames.
call each separatly eg
<BODY>
<?php
echo "<H1>Welcome to MySite</H1>";
?>
<%
// all the asp stuff, perl stuff or whatever...
%>
<?php
echo "footer stuff";
?>