some suggestions to streamline this:
PHP Code:
<?php
// pages user is allowed to navigate to
// assoc. array with "filename" => "File Title" pairs
// also used to make navigation, so adding/removing pages is easy
$nav = array('site1'=>'Site 1','site2'=>'Site 2','site3'=>'Site 3','site4'=>'Site 4');
// check if request is set and is allowed
// if not, leave blank (your 404 will catch it)
// or you could define a default page as you were discussing above
$site = isset($_GET['site']) && in_array($_GET['site'], $nav)? $_GET['site']: '';
// the above eliminates the need for your eregi() function
// which, BTW, is _depreciated_: you should use preg_match() instead.
// loop through menu items
foreach($nav as $key => $val){
// if current menu item matches current page, add "selected" class
// otherwise leave it blank
$selected = $key === $site? ' class="selected"': '';
// build hyperlink
$navlinks[] = '<a href="index.php?site='. $key .'"'. $selected .'>'. $val .'</a>';
}
$links = implode("\n",$navlinks);
if(!file_exists('content/'.$site.'.php')){ $site = '404'; header("HTTP/1.0 404 Not Found"); }
?>
<!DOCTYPE html>
<html>
<head>
<!-- you need to declare your charset -->
<title>CChawps</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<nav>
<?php print $links; ?>
</nav>
<div id="content">
<!-- incidentially, I would use absolute URL here.
like "http://mysite.com/content/".$site.".php" -->
<?php include("content/". $site .".php"); ?>
</div>
</body>
</html>
Bookmarks