English 中文(简体)
如何在不同页上显示同样的头盔和脚步?
原标题:How to display same header and footer on different pages?

我任团长。 php和脚本。 php文件,我在所有页页都有。 样页照相:

<?php include($_SERVER[ DOCUMENT_ROOT ]. /header.php );?>

<div id="content">
...
</div> <!-- content -->

<?php include($_SERVER[ DOCUMENT_ROOT ]. /footer.php ) ?>

虽然这在服务器上运行良好,但当我在当地测试页[视窗7上Xampp]时,我收到以下错误信息,而不是头盔,同样是脚 -——

Warning: include(C:/xampp/htdocs/header.php) [function.include]: failed to open stream: No such file or directory in C:xampphtdocsfindex.php on line 1

Warning: include() [function.include]: Failed opening  C:/xampp/htdocs/header.php  for inclusion (include_path= .;C:xamppphpPEAR ) in C:xampphtdocsfindex.php on line 1

这使测试变得非常麻烦,因为我不得不向服务器上载,以应付每一小变化。

此外,我还围绕《工作计划》守则,并利用一位老头来展示头盔。 php档案。 我不能完全理解这一职能。 我的网站没有使用WP。

包括头盔和脚 the档案的正确方式是什么?

最佳回答

看来,<代码>_SERVER[DOCUMENT_ROOT]指的是C:xampphtdocs,而你的字母为C:xampphtdocsf,核对_$_ SERVER[DOCUMENT_ROOT] on their local environment.

编辑:

<?php
$rootDir = "";
if(strpos($_SERVER[ HTTP_HOST ], localhost )===FALSE)
{
  //On Production
  $rootDir = $_SERVER[ DOCUMENT_ROOT ];
}
else
{
  //On Dev server
  $rootDir = $_SERVER[ DOCUMENT_ROOT ]. /f ;
}

<?php include($rootDir. /header.php );?>

<div id="content">
...
</div> <!-- content -->

<?php include($rootDir. /footer.php ) ?>


?>
问题回答

列入任何档案的正确方法是包括()或要求()职能。 由于头盔只是1个档案,所以压缩使用“头盔”的功能,因此他们为产出创造了功能。

你的问题似乎与“SERVER”变量有关。 自从我与公共卫生和社会福利部合作以来,时间已相当长,但我建议你做的是,只是使用相对的道路。 例如,如果是负责人的话。 php和脚本。 php的档案与你的索引相同。 php,你可以这样做:

<?php include("header.php );?>

<div id="content">
...
</div> <!-- content -->

<?php include( footer.php ) ?>

<>Simple和useful way(我在所有项目中使用):

// find Base path
define(  BASE_PATH , dirname(__FILE__) );

// include files
include BASE_PATH .  /header.php ;
include BASE_PATH .  /footer.php ;




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签