you should use includes. make a file called head.php and put all your logic that appears on every page in there.
PHP Code:
<?
// head.php
// set mysql connection
$username="abc123";
$password="abc123";
$database="abc123";
$host="localhost";
$conn = mysql_connect("$host","$username","$password") or die('Could not connect: ' . mysql_error());
mysql_select_db($database) or die('Could not select database');
// declare function
function WriteLog() {
$query="INSERT INTO logs SET date=CURDATE(), time=CURTIME()";
$results=mysql_query($query);
}
// call function
WriteLog();
?>
same thing for the bottom of every page, let's call this foot.php
PHP Code:
<?
// foot.php
mysql_close();
// any other logic you want at the end of each page
?>
now, a regular page might look like this:
PHP Code:
<?
include("includes/head.php");
?>
<html>
<head>
<title> my page</title>
</head>
<body>
<h1>my web page</h1>
</body>
</html>
<?
include("includes/foot.php");
?>