我的php includes有问题,我想知道是否有人能告诉我的代码有什么问题。这就是我的文件集的分解方式。
我有两个索引文件。一个在bank''index.php,一个在bank''onlinebanking''index.php.
我把页眉和页脚分成了两个不同的文件。它们被列为bank''header.inc.php和bank''footer.inc.php。我从整个网站的标题中捕获了我的css。
标题包括:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Banking Home Page</title>
</head>
<body class="body">
<link href="../_assets/stylesheets/style.css" rel="stylesheet" type="text/css" />
<div>
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="_assets/images/bkrnd_top.png">
<tr>
<td width="50%"><img border="0" src="../_assets/images/bkgrnd_tl.png" width="205" height="61"></td>
<td width="50%">
<p align="right"><img border="0" src="../_assets/images/logo.png" width="160" height="61"></td>
</tr>
</table>
</div>
<div>
<table border="0" width="100%" cellspacing="1" cellpadding="0" background="_assets/images/background_headerarea.png">
<tr>
<td width="100%"><font face="Arial" size="2"><b> <font color="#FFFFFF">HOME | TBA | TBA | TBA | TBA | TBA</font></b></font></td>
<td>
</tr>
</table>
<?php require_once('login.inc.php'); ?>
我遇到的问题是,我无法让我的css或_assets为我的两个inex文件正确呈现。
如果我将链接更改为类似src="../_assets/images/bkgrnd_tl.png"的内容,它将正确显示在bank''onlinebanking''index.php中,但不会显示在bank'' index.php中
我希望你明白我想说的话。我只想在所有页面上呈现所有css的一个页眉和页脚。
我的包含内容如下:
bank''onlinebanking''index.php=
require_once('../websiteconfig.inc.php'); require_once('../header.inc.php'); ?>
bank''index.php
样式表链接应包含在标题部分中,如以下
<head>
<link href="../_assets/stylesheets/style.css" rel="stylesheet" type="text/css" />
</head>
您遇到的问题只是到各种文件的路径不同。例如:
home_directory/bank/index.php
home_directory/bank/onlinebanking/index.php
链接路径的".."部分表示"更上一层楼"。
对于上面的第一个文件,它将转到home_directory/
。但是,对于第二个文件,则转到home_directory/bank
。
你有两个潜在的解决方案。一种方法是将所有代码文件移动到相同的目录深度。例如:
home_directory/bank/index.php
home_directory/onlinebanking/index.php
第二种,可能也是更可取的一种,是通过根相对路径引用您的附加工件。换句话说,不使用../whatever
,只使用/whatever
在您的情况下,它将是:href="/_assets/stylesheets/style.css"
define("PATH", "http://www.mysite.com");
然后你可以做一些类似的事情:
<img border="0" src="<?php echo PATH; ?>/_assets/images/bkgrnd_tl.png" width="205" height="61">
您也可以设置多条通往不同区域的路径,例如主题路径。
CSS文件是否用作text/CSS?复制URL并直接进入其中,然后使用Firefox右键单击并查看页面信息,或者使用Opera的F4-->信息面板查看mime/media类型。您也可以使用Fiddler 2。
您可以使用以下命令手动设置CSS文件,以便在.htaccess文件中正确提供服务。。。
AddType text/css .css
如果您有更具体的需求,可以使用PHP手动设置mime/media类型,方法如下。。。
<?php
header('Content-Type: text/css');
?>
我所做的是创建一个配置文件。在配置文件中,我使用了一个绝对引用。
define('ABSOLUTE_PATH', '/home/mjcrawle/bank/');
然后我使用了以下php-include使其正确渲染。
require_once('../websiteconfig.inc.php');
include(ABSOLUTE_PATH . 'header.inc.php');