2014-05-07 90 views
2

我一直在使用PHP构建网站。我对使页面正确显示的方法或技巧感到困惑。使用.html和.php对页眉和页脚进行说明

我的主要入门点是index.html。从这里,用户可以点击浏览。我希望所有12个页面具有相同的标题信息。 我试过在Dreamweaver中使用标签,然后只是标签。

??我感到困惑的使用标签和使用 文件之间的差异被称为header.php

跟进:要建议的对策。我编辑代码建议
现在,当我'在浏览器中查看'我得到'服务器未找到'。

注意。我使用DreamweaverCC:

文档根目录/库/ Web服务器/文件

的header.php

<!doctype html> 
<head> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 

<body> 
    <h1>General Header Information for Top of Each Page</h1> 

的index.html

<?php include_once ('header2.php'); ?> 
<!doctype html> 
<head> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>index.php</title> 
<link href="file:////Library/WebServer/Documents/webDevelopDWsites  /boilerplate.css" rel="stylesheet" type="text/css"> 
<link href="file:///Library/WebServer/Documents/webDevelopDWsites/indexFourSquare.css" rel="stylesheet" type="text/css"> 

<script src="file:///Library/WebServer/Documents/webDevelopDWsites/respond.min.js"> </script> 
</head> 
<body> 

<?php include 'header2.php'; ?> 
    <div class="gridContainer clearfix"> 
    <div id="div1" class="fluid"> 
    <header id="header" class="fluid">Web Development by myName</header> 

    <div id="Square1" class="fluid"><a href="file:///Library/WebServer/Documents /webDevelopDWsitesimages/Square1.jpg"><img src="images/Square1.jpg" alt=""/></a></div> 

    <div id="Square2" class="fluid"><a href="file:///Library/WebServer/Documents/webDevelopDWsites/Square2.html"><img src="images/Square2.jpg" alt=""/></a></div> 

    <div id="Square3" class="fluid"><a href="file:///Library/WebServer/Documents/webDevelopDWsites/Square3.html"><img src="images/Square3.jpg" alt=""/></a></div> 

    <div id="Square4" class="fluid"><a href="file:///Library/WebServer/Documents/webDevelopDWsites/Square4.html"><img src="images/Square4.jpg" alt=""/></a></div> 

    <div id="siteMap" class="fluid">siteMap</div> 
    </div> 
</div> 
</body> 
</html> 

我是否包括header.php在每个其他网页的代码中?我做了这个,但没有奏效。

所以我试过这个:我创建了一个index.php并将所有的index.html代码复制到index.php中,并且在代码的顶部添加了这个代码。

<?php include 'header.php'; ?> 

当我使用 '在浏览器中查看' 启动index.html: '无头信息'

  • 我得到的网页正确

当我在图像上点击浏览到其他页面,它的工作原理:

  • 但“没有头信息”。

当我点击index.php

  • 我只得到了标题信息。
+0

默认情况下,您必须为您的扩展名指定“.php”。否则,你的php代码将不会被解释。 – OpenStark

+0

@iHaveAQuestion编辑中的禁用术语是什么?我改变了标题,以便您的问题更容易找到,并且您可能会得到更多答案。 –

+0

@icanhascheezburger进展。 '无法连接'文档根目录库/ Web服务器/文档。我创建了一个新文件夹:Library/WebServer/Documents/dwwdSite(= DreamWeaverWebDevelopmentSite)。但是当我输入URL localhost/dwwdSite/error:'无法连接'。 dwwdSite的网站设置:name = localhost。地址= macHD/library/WebServer/Documents。连接=本地/网络。测试检查。本地信息网址:Http:// localhost /。网站名称= dwwdSite。本地站点文件夹=/Library/WebServer/Documents/dwwdSite。我觉得在这些设置中我必须有不正确的东西。仍然'无法连接'。 – iHaveAQuestion

回答

3

通常情况下,一个网站被分为3个部分:

enter image description here

页眉和页脚遵循所有的页面,这仅仅是那间变化。所以在你的头上。PHP,你将有:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>headerForFourSquares 
</title> 
</head> 
<body>  
     <h1>General Header Information for Top of Each Page.</h1> 

就是这样,没有在这里结束的<body>标签。

现在,在您的index.php ,你会怎么做:

<?php include_once('header.php'); ?> 

//all your index content here 

<?php include_once('footer.php'); ?> 

最后footer.php

</body> 
</html> 

这是它的工作方式。对于其他每个页面,您都应该包含上面的页眉和页脚。

您的索引文件扩展名为.php。如果他们没有PHP代码,则页眉和页脚文件可以是.html扩展名。

You say index.html is not going to execute any php code but you do not explain why.

当你在你的.html文件的PHP代码,当浏览器打开一个.html文件,其中包含PHP代码,它不希望任何PHP代码是存在,因此不解释它。虽然,你可以强制它解释下面的here PHP,但这本身是一个不好的做法,因为其他语言如<?xml之间可能会出现冲突,因为PHP也以<?开头。

,以及为什么需要通过本地主机,而不是通过浏览器打开该文件路径来运行它的原因是因为,虽然HTML是一种客户端脚本,它可以自由地,没有任何服务器上运行,但PHP是一个服务器 - 并且将被服务器解释为只有,这就是为什么我们使用web服务器软件包(如xampp,wamp等)在本地进行测试的原因。

+2

有关'index.html'的注意事项,许多动态网站使用它们各自的语言扩展名作为引导文件。然而,他们通过重写URL(例如apache mod重写)将它们伪装为纯HTML文件。这就是为什么他们尽管出现静态html文件动态。 – Flosculus

+0

我很欣赏这个反馈。此评论框仅允许500个以上的字符。我想包括我的代码。我该怎么做呢 ????当我启动index.php时,我收到'服务器未找到错误'。当我启动(在浏览器中查看)index.html时,我不明白这一点。 – iHaveAQuestion

+0

@iHaveAQuestion index.html不会执行任何PHP代码,因此您可以忘记它,至于代码,您可以编辑上面的问题并粘贴。 –