我正在尝试建立一个包含大量网页的网站。 我有根index.php页面,其中包含一些表格,包括标题,菜单,侧边栏,页脚和正文页面(显示我们要求的内容)。 我将一个页面与我的一个菜单项链接在一起,当我点击链接时,它只打开资源文件。我需要打开带有标题和我网站其他元素的页面。帮助我,谢谢
<body>
<div>
<?php Include('header.php');
</div>
<div id="menu" align="center">
<table width="790" height="35">
<tr>
<td> Home
</td>
<td><a href="pages/students/reg.php">Register</a>
</td> // this page need to display on the same window with other elements, after click.
</tr>
</tabel>
</div>
<div id="sidebar" align="right">
<?php include ("sidebar.php");
?>
</div>
<div id="Content ">
<?php
include("FILE"); // here i need to display the hyper linked page.
?>
</div>
<div id="footer">
<?php include("footer.php");
?>
</div>
</body>
答案 0 :(得分:1)
//menu area
<div id="menuWrap">
<a href="?page=page1">link to page1</a>
<a href="?page=page2">link to page2</a>
</div>
//side bar
<div id="sidebarWrap">...</div>
//content area
<div id="contentWrap">
<?php
switch($_GET['page'])
{
case 'page1':
include '/pages/page1.php';
break;
case 'page2':
include '/pages/page2.php';
break;
default:
include '/pages/notfound.php';
}
?>
</div>
//footer
<div id="footerWrap">...</div>
这样,您可以在同一窗口中显示站点中的其他页面,只会更改内容区域
更新
我已经纠正了你的拼写错误,根据你的代码段,这是答案。
<body>
<div>
<?php Include('header.php'); ?>
</div>
<div id="menu" align="center">
<table width="790" height="35">
<tr>
<td><a href="?page=page1">Home</a></td>
<td><a href="?page=page2">Register</a></td>
</tr>
</table>
</div>
<div id="sidebar" align="right">
<?php include ("sidebar.php"); ?>
</div>
<div id="Content ">
<?php
switch($_GET['page'])
{
case 'page1':
include '/pages/home.php';//file path of your home page
break;
case 'page2':
include '/pages/students/reg.php';
break;
default:
include '/pages/notfound.php';
}
?>
</div>
<div id="footer">
<?php include("footer.php");?>
</div>
</body>
答案 1 :(得分:0)
首先,创建一个具有以下名称的文件:(包括点)
的.htaccess
并将其放在索引的同一文件夹中。
在.htaccess中,编写以下代码:
# .htaccess mod_rewrite
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
此案例中的.htaccess将重写网址以更改 http://127.0.0.1/index.php?page=register 以接受“博客漂亮网址” http://127.0.0.1/register
在index.php文件夹中,创建一个新文件夹“pages”。
在文件夹页面内,创建4个简单的PHP文件(home.php,register.php,anyother.php和notfound.php),其中包含任何内容,如
<?php
echo "I'm the Register Page.";
?>
这将是基于您的代码的索引示例。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>¨title</title></head>
<body>
<div>
<?php include 'header.php'; ?>
</div>
<div id="menu" align="center">
<table width="790" height="35">
<tr>
<td><a href="/home">Home</a></td>
<td><a href="/register">Register</a></td>
<td><a href="/anyother">AnyOther</a></td>
<td><a href="/misstypo" title="This will lead to the notfound.php">Broken Sample</a></td>
</tr>
</table>
</div>
<div id="sidebar" align="right">
<?php include 'sidebar.php'; ?>
</div>
<div id="Content ">
<?php
if(!isset($_GET['page']) || $_GET['page'] == ''){
$page = 'home'; //If no page specified
} else {
$page = $_GET['page'];
}
switch($page)
{
case 'home':
include '/pages/home.php';//file path of your home page
break;
case 'register':
include '/pages/register.php';
break;
case 'anyother':
include '/pages/anyother.php';
break;
default:
include '/pages/notfound.php'; //If any page that doesn't exists, then get back to home.
}
?>
</div>
<div id="footer">
<?php include("footer.php");?>
</div>
</body>
</html>