The newbie notice here...ok I tried searching this but since I'm am not exatcly sure of the terms that I should be looking for I'm not coming up with what I want.
To make this simple, I have a web site that I want to be able to change a portion of the web page without having to reload the header, sidebar, footer and so on. Here is what I have so far for the index:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<body>
<div style="height:50px;border:1px solid #000;margin-bottom:10px">
</div>
<div style="float:left;width:15%;border:1px solid #000">
<ul style="margin-left:10px;list-style-type:none">
<li><a href="index.php">Home</a></li>
<li><a href="index.php?page=about">About</a></li>
<li><a href="index.php?page=contact">Contact</a></li>
</ul>
</div>
<div style="float:right;width:80%;border:1px solid #000">
<div style="padding:4px">
<!-- content here -->
</div>
</div>
</body>
</html>
Now there are other php pages of course, such as about, contact, and more but for simplicity I am starting small. Now to change the pages I know I need to use this code:
<?php
default page
$default = 'home.php';
set document root path
$base = $_SERVER['DOCUMENT_ROOT'];
list of all site pages + the id they will be called by
$pages = array('about' => 'about.php','contact' => 'contact.php');
if(array_key_exists($GET['page'], $pages))
{
foreach($pages as $pageid => $pagename) {
if($GET['page'] == $pageid && file_exists($base.$pagename))
{
/ if somebody's making a request for ?page=xxx and
the page exists in the $pages array, we display it
checking first it also exists as a page on the server /
include $base.$pagename;
}
} // end foreach
}
else {
/ if the page isn't listed in $pages, or there's no ?page=xxx request
we show the default page, again we'll also just make sure it exists as a file
on the server /
if(file_exists($base.$default)) include $base.$default;
}
?>
My problem is I do not know where to exactly put this code to get it to work. I thought that I would have to place it within the index.php page. If you notice in my index.php text that I put first I have a <!-- content here --> section where I thought that it should go. However, it is not working.
Anyone willing to help me out so I figure this out?
Thanks,
VTTV