PHP-CSS/PHP包括

PHP-CSS/PHP包括,php,include,Php,Include,我的php包含有问题,我想知道是否有人可以告诉我的代码可能有什么问题。这就是我的文件集的分解方式 我有两个索引文件。一个在bank\index.php中,一个在bank\onlinebanking\index.php中 我已将页眉和页脚拆分为两个不同的文件。它们被列为 bank\header.inc.php和bank\footer.inc.php。我从整个网站的标题中捕获css 标题包括: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans

我的php包含有问题,我想知道是否有人可以告诉我的代码可能有什么问题。这就是我的文件集的分解方式

我有两个索引文件。一个在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>&nbsp;&nbsp; <font color="#FFFFFF">HOME&nbsp;&nbsp; |&nbsp;&nbsp; TBA&nbsp;&nbsp; |&nbsp;&nbsp; TBA&nbsp;&nbsp; |&nbsp;&nbsp; TBA&nbsp;&nbsp; |&nbsp;&nbsp; TBA&nbsp;&nbsp; |&nbsp;&nbsp; TBA</font></b></font></td>

<td>

</tr>


</table>
<?php require_once('login.inc.php'); ?>
bank\index.php


CSS文件是否用作文本/CSS?复制URL并直接进入其中,然后使用Firefox右键单击并查看页面信息,或者使用Opera的F4-->信息面板查看mime/媒体类型。您也可以使用Fiddler 2

您可以使用以下命令手动设置CSS文件,以便在.htaccess文件中正确提供服务

AddType text/css .css
如果您有更具体的需求,可以使用PHP以下方式手动设置mime/媒体类型

<?php
header('Content-Type: text/css');
?>

设置一些路径变量可能会对您有所帮助。然后,您可以在所有图像和css上提供一个绝对路径。比如:

define("PATH", "http://www.mysite.com");
<img border="0" src="<?php echo PATH; ?>/_assets/images/bkgrnd_tl.png" width="205" height="61">
然后,您可以执行以下操作:

define("PATH", "http://www.mysite.com");
<img border="0" src="<?php echo PATH; ?>/_assets/images/bkgrnd_tl.png" width="205" height="61">
/\u assets/images/bkgrnd\u tl.png“width=“205”height=“61”>

您也可以设置指向不同区域的多个路径,例如主题路径。

样式表链接应包含在标题部分,如下所示

<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/bank/index.php  
home_directory/onlinebanking/index.php
链接路径的“.”部分显示“再上一级”

对于上面的第一个文件,它将转到
home\u目录/
,但是对于第二个文件,它将转到
home\u目录/bank

您有两种可能的解决方案。一种方法是将所有代码文件移动到相同的目录深度。例如:

home_directory/bank/index.php  
home_directory/bank/onlinebanking/index.php
home_directory/bank/index.php  
home_directory/onlinebanking/index.php
第二个,可能也是更可取的一个,是通过根相对路径引用您的其他工件。换句话说,不要使用
。/whatever
,只需使用
/whatever


在您的情况下,它将是:
href=“/\u assets/stylesheets/style.css”

我所做的是创建一个配置文件。从配置文件我使用了一个绝对引用

define('ABSOLUTE_PATH', '/home/mjcrawle/bank/');
然后,我使用以下php include来正确地呈现它

 require_once('../websiteconfig.inc.php');
 include(ABSOLUTE_PATH . 'header.inc.php'); 

我以前从未使用过那个标签。我会检查一下的,谢谢。