John_Saunders
01-09-2003, 02:39 AM
I wrote a PHP template script and was wondering if a PHP guru would look over my code and see if there's any security holes. If you see a better way to do something instead of how I coded it please point it out. :)
Also, how can I make a printer friendly page so a visitor can click on a link like: http://www.domain.com/index.php?section=about&page=resume&action=print and it will come up with a page with nothing but the content from the PHP file containing the main content and not the header and footer?
Here are the main files that contain the code.
index.php [template]
<?php
// format directory/page names for page title
$sectiontitle = str_replace("_", " ", $section);
$pagetitle = str_replace("_", " ", $page);
$st = ucwords($sectiontitle);
$pt = ucwords($pagetitle);
$title = "My Site | " . $st . " | " . $pt ."";
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//w3c//dtd xhtml 1.0 transitional//en"
"http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title><?php print $title ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="700" cellpadding="0" cellspacing="0" align="center" border="1">
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/header.php" ?></td>
</tr>
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/navigation.php" ?></td>
</tr>
<tr>
<td width="150" valign="top">
<?php
/* This code is for the sub navigation links that change
based on what section of the site the visitor is viewing */
$subnav = Array('home','about','links','contact');
$sn = (!isset($_GET['section']) ) ? 'no section' : (!in_array($_GET['section'], $subnav)) ? 'home' : $_GET['section'] ;
$subnav = "includes/subnavigation/" . $sn . ".php";
include($subnav);
?>
</td>
<td width="550" valign="top">
<?php
/* This code pulls the main content for the page. */
$content = Array('overview','resume','references');
$c = (!isset($_GET['page']) ) ? 'no page' : (!in_array($_GET['page'], $content)) ? 'overview' : $_GET['page'] ;
$content = "includes/" . $sn . "/" . $c . ".php";
include($content);
?>
</td>
</tr>
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/footer.php" ?></td>
</tr>
</table>
</body>
</html>
includes/navigation.php [main navigation links]
<?php
// home
if ($section == "" || $section == home) {
print "Home ";
}
else {
print "<a href=\"index.php?section=home\">Home</a> ";
}
// about
if ($section == about) {
print "About ";
}
else {
print "<a href=\"index.php?section=about\">About</a> ";
}
// links
if ($section == links) {
print "Links ";
}
else {
print "<a href=\"index.php?section=links\">Links</a> ";
}
// contact
if ($section == contact) {
print "Contact ";
}
else {
print "<a href=\"index.php?section=contact\">Contact</a> ";
}
?>
includes/subnavigation/about.php
<?php
// overview
if ($page == overview) {
print "Overview<br>";
}
else {
print "<a href=\"index.php?section=about&page=overview\">Overview</a><br>";
}
// resume
if ($page == resume) {
print "Resume<br>";
}
else {
print "<a href=\"index.php?section=about&page=resume\">Resume</a><br>";
}
// references
if ($page == references) {
print "References<br>";
}
else {
print "<a href=\"index.php?section=about&page=references\">References</a><br>";
}
?>
Any advice would be greatly appreciated.
Regards,
John
Also, how can I make a printer friendly page so a visitor can click on a link like: http://www.domain.com/index.php?section=about&page=resume&action=print and it will come up with a page with nothing but the content from the PHP file containing the main content and not the header and footer?
Here are the main files that contain the code.
index.php [template]
<?php
// format directory/page names for page title
$sectiontitle = str_replace("_", " ", $section);
$pagetitle = str_replace("_", " ", $page);
$st = ucwords($sectiontitle);
$pt = ucwords($pagetitle);
$title = "My Site | " . $st . " | " . $pt ."";
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//w3c//dtd xhtml 1.0 transitional//en"
"http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title><?php print $title ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="700" cellpadding="0" cellspacing="0" align="center" border="1">
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/header.php" ?></td>
</tr>
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/navigation.php" ?></td>
</tr>
<tr>
<td width="150" valign="top">
<?php
/* This code is for the sub navigation links that change
based on what section of the site the visitor is viewing */
$subnav = Array('home','about','links','contact');
$sn = (!isset($_GET['section']) ) ? 'no section' : (!in_array($_GET['section'], $subnav)) ? 'home' : $_GET['section'] ;
$subnav = "includes/subnavigation/" . $sn . ".php";
include($subnav);
?>
</td>
<td width="550" valign="top">
<?php
/* This code pulls the main content for the page. */
$content = Array('overview','resume','references');
$c = (!isset($_GET['page']) ) ? 'no page' : (!in_array($_GET['page'], $content)) ? 'overview' : $_GET['page'] ;
$content = "includes/" . $sn . "/" . $c . ".php";
include($content);
?>
</td>
</tr>
<tr>
<td width="700" colspan="2" align="center"><?php include "includes/footer.php" ?></td>
</tr>
</table>
</body>
</html>
includes/navigation.php [main navigation links]
<?php
// home
if ($section == "" || $section == home) {
print "Home ";
}
else {
print "<a href=\"index.php?section=home\">Home</a> ";
}
// about
if ($section == about) {
print "About ";
}
else {
print "<a href=\"index.php?section=about\">About</a> ";
}
// links
if ($section == links) {
print "Links ";
}
else {
print "<a href=\"index.php?section=links\">Links</a> ";
}
// contact
if ($section == contact) {
print "Contact ";
}
else {
print "<a href=\"index.php?section=contact\">Contact</a> ";
}
?>
includes/subnavigation/about.php
<?php
// overview
if ($page == overview) {
print "Overview<br>";
}
else {
print "<a href=\"index.php?section=about&page=overview\">Overview</a><br>";
}
// resume
if ($page == resume) {
print "Resume<br>";
}
else {
print "<a href=\"index.php?section=about&page=resume\">Resume</a><br>";
}
// references
if ($page == references) {
print "References<br>";
}
else {
print "<a href=\"index.php?section=about&page=references\">References</a><br>";
}
?>
Any advice would be greatly appreciated.
Regards,
John