使用PHP构建的网站包括头部内容

时间:2014-06-24 15:30:51

标签: php html include doctype

我接管了一个基于PHP构建的网站。基本上,大多数页面在IE中都没有正确显示,我之所以这样做是因为DOCTYPE没有设置好。

经过进一步调查,似乎所有头信息(包括DOCTYPE)都在一个名为header.php的PHP包含文件中,这是公平的,但是在没有正确加载的页面上,在此之前有代码包括被调用,这就是没有设置DOCTYPE的原因。

将header.php的include移动到代码的第一行很容易,但第一行代码是PHP变量,包括关键字,页面描述和页面标题,header.php包含然后是指。如果我将包含代码移到这些变量之上,那么header.php将不会知道关键字,页面标题或描述,因为它们尚未设置。

整个网站都是这样构建的 - 不确定它是如何工作的。

有什么方法可以让我看不到吗?我已经将header.php文件的一部分包含在下面没有正确显示的页面中。

感谢任何帮助,感谢您花时间阅读本文。

header.php - >

    <!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><?php echo $pageTitleDisp ?></title>
    <meta name="keywords" content="<?php echo $pageKeywords?>" />
    <meta name="description" content="<?php echo $pageDesc?>" />
    <meta http-equiv="content-language" content="en-gb" />
    <meta name="copyright" content="My company" />
    <meta name="revisit-after" content="3 days" />
    <meta name="Robots" content="index, follow" />
    <meta name="Robots" content="all" />
    <meta name="Distribution" content="Global" />
    <meta name="Author" content="Me"/>
    <meta name="Accessibility" content="WCAG Double-A" />
    <meta name="Audience" content="All Users" />
    <meta name="Coverage" content="UK" />
    <meta name="Language" content="English" />
    <meta name="Rights" content="Reproduction by Permission Only" />
    <meta name="Rights.Copyright" content="My company" />
    <meta name="Type" content="Web Page" />
    <link href="<?php echo $canonical; ?>"  rel="canonical" />
    <link href="/css/webstyle.css" rel="stylesheet" type="text/css" />
    <script src="/js/site-functions.js" type="text/javascript"></script>
    <!--[if IE 6]><style type="text/css">img,div { behavior: url(/js/iepngfix.htc) }</style><![endif]-->
    <!--[if IE 7]><link href="/css/ie7.css" rel="stylesheet" type="text/css" /><![endif]-->  

然后这是一个页面,然后调用上面的header.php信息:

    <?php include("../includes/config.php"); ?>
    <?php 
    // SEO TAGGING 
    $pageTitleDisp="Page Title";
    $pageKeywords="cars planes bikes";
    $pageDesc="this is a webpage that looks pap in IE";
    $canonical="http://mydomain.com/about/";
    ?>
    <?php $popbox="true"; ?>
    <?php include("../includes/header.php"); ?>

经过一些有用的人的建议后,似乎只有调用config.php的页面才有这个问题。下面是config.php文件 - 如果有人有时间或知识发现可能导致问题的原因,我将非常感激。如果我注释掉config.php的调用,那么该页面根本就不显示!

    <?php
$user="user";
$password="password";
$database="DB";
mysql_connect("my.database.com",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

$bulkPrice="24.99";
$singlePrice="3.49";

function makeClickableLinks($text) {

  $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
    '<a href="\1" target="_blank">\1</a>', $text);
  $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
    '\1<a href="http://\2" target="_blank">\2</a>', $text);
  $text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
    '<a href="mailto:\1" target="_blank">\1</a>', $text);

return $text;

}

function multiInsert($table,$cols){
                $cols= explode(",", $cols);

                     foreach ($cols as $colname) {
                                            $sqlinsert1.= "$colname, ";
                                            global $$colname;
                                            if ($colname=="dateAdded")
                                                        {
                                                        $sqlinsert2.= "Now(), ";
                                                        }
                                                    else {
                                                        $sqlinsert2.= "'".$$colname."', ";
                                                        }
                                              }
                        $sqlinsert1=removeComma($sqlinsert1);
                        $sqlinsert2=removeComma($sqlinsert2);               
                        $sqlinsert= "($sqlinsert1) values ($sqlinsert2)";

                $query="insert into $table $sqlinsert ";
                $result=mysql_query($query)or die(  mysql_error()."<BR><BR><B>$query</b>"); 
                return mysql_insert_id();
}


function cleanUserText ($para){

    $para=html_entity_decode($para);

  $array = array("itxtvisited=\"1\"","<EM>","<EM >","</EM>","<em>","</em>","<i>","</i>");
  $para = str_replace($array, "", $para);

$para = str_replace("\n", "<BR>", $para);
$para = str_replace("\n\b", "<BR>", $para);

  $para = str_replace("&amp;quot;", "\"", $para);
      $para = str_replace("&amp;", "&", $para);

     $para = str_replace("•", "&middot;", $para);
     $para = str_replace("’", "'", $para);
    $para = str_replace("®", "", $para);
    $para = str_replace("™", "", $para);
    $para = str_replace("…", "...", $para);
   $para = str_replace("“", "\"", $para);
   $para = str_replace("”", "\"", $para);


    $para = str_replace('<span style="font-weight: bold;">', "<B>", $para);
        $para = str_replace('<span style="font-weight: bold;" class="largeblack">', "<B>", $para);
         $para = str_replace('<i style="font-weight: bold;">', "<B>", $para);
      $para = str_replace('BACKGROUND: white', "", $para);

     $para = str_replace('</span>', "</B>", $para);

        $search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
                '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
               '@<![\s\S]*?--[ \t\n\r]*>@',        // Strip multi-line comments including CDATA
                '@<SPAN[^>]*?>@siU',    // Strip style tags properly
                '@</SPAN>@siU',    // Strip style tags properly
                '@<FONT[^>]*?>@siU',    // Strip style tags properly
                '@</FONT>@siU',    // Strip style tags properly
                    );
        $para = preg_replace($search, '', $para);

$para=makeClickableLinks($para);

    return $para;


}




function encLink($name){
    $name=strtolower($name);
$name=str_replace(" ","-",$name);
return "$name";


}

function decLink($name){
    $name=strtoupper($name);
$name=str_replace("-"," ",$name);
return "$name";


}


function getColours(){

    global $colours;

$query="SELECT * from colours";
$result=mysql_query($query)or die(mysql_error()); ;

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
            foreach($row as $k => $v){$$k = $v;}
            $colours["$colourID"]="$colourTitle";
                }   
}


function dispCatLink($catsLink){


$catsList = explode(",", $catsLink); 
$catsLink1=$catsList[0];


$query="SELECT * FROM cats  where catID = $catsLink1";
$result=mysql_query($query)or die(mysql_error()."Query is: <b>$query</b>"); 
$row = mysql_fetch_assoc($result);
if ($row){foreach($row as $k => $v){$$k = $v;}}


$catTitleF=str_replace(" ","-",$catTitle);
echo "<a href=/$catTitleF/products/>$catTitle</a>";

}

function alertMSG($alerter){

if ($alerter) echo "<div ID=alerter><img src=/icon/asterisk_yellow.png class=icn width=16 height=16 />$alerter</div>";

}

function open_image ($file) {
        # JPEG:
        $im = @imagecreatefromjpeg($file);
        if ($im !== false) { return $im; }
        # GIF:
        $im = @imagecreatefromgif($file);
        if ($im !== false) { return $im; }
        # PNG:
        $im = @imagecreatefrompng($file);
        if ($im !== false) { return $im; }
        # WBMP:
        $im = @imagecreatefromwbmp($file);
        if ($im !== false) { return $im; }
       # Try and load from string:
        $im = @imagecreatefromstring(file_get_contents($file));
        if ($im !== false) { return $im; }
        return false;
}

function upFile($upfile){


    if ($_FILES[$upfile]['tmp_name']){


                $newName= str_replace(" ","_",basename( $_FILES[$upfile]['name']));
                    $dest=  $_SERVER[DOCUMENT_ROOT]."/uploads/".$newName;
                    if(move_uploaded_file($_FILES[$upfile]['tmp_name'], $dest)) {

                         return $newName;
                    }
                    else {
                        echo $_FILES[$upfile]['name']." - There was an error uploading the file, please try again!";

                        return "";
                    }
        }
        else {
            return "";
        }

}



    function multiUpdate($table,$clause,$cols){
                $cols= explode(",", $cols);

                     foreach ($cols as $colname) {
                                            global $$colname;
                                            $sqlinsert.= " $colname = '".$$colname."',";
                                }

                    $sqlinsert=removeComma($sqlinsert);


                    global $$clause;

                $query="update $table set $sqlinsert where $clause=".$$clause;
                $result=mysql_query($query)or die(  mysql_error()."<BR><BR><B>$query</b>");

}

  function removeComma($var){
        if(substr($var, -1)==","){$var = substr($var,0,-1);}
        if(substr($var, -2)==", "){$var = substr($var,0,-2);}
        return $var;
                        }


function conv($size){

$converted=2.54*$size;
$converted= sprintf("%01.0f", $converted);

if ($converted=="0"){$converted="N/A ";}
return $converted;
}

function dispThumbs($prodID,$max_i,$size){



        for ($i=1; $i<=$max_i; $i++)  {

         $filename=$_SERVER['DOCUMENT_ROOT']."/prodImages/$size/".$prodID."/".$i.".jpg";

            if (file_exists($filename)) {
                        echo "<a href='/photos/$prodID/$i/'><img  border=0 class='imgTH' width=100 height=67 src=/prodImages/$size/".$prodID."/".$i.".jpg></a>";

                }

        }
}



        function open_dir ($dir){
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                        if (preg_match ("/.jpg/i", "$file")){
                        $files.="$file,";
                    }
                }
                closedir($dh);
            }
        }
        if(substr($files, -1)==","){$files = substr($files,0,-1);}
        return $files;
}



  function sec2hms ($sec, $padHours = false) 
  {

    $hms = "";

    $hours = intval(intval($sec) / 3600); 

//    $hms .= ($padHours) 
   //       ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
  //       : $hours. ':';

    $minutes = intval(($sec / 60) % 60); 

    $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';

    $seconds = intval($sec % 60); 

    $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);

    return $hms;

  }

     function checkIMG($imgLink){

    if (file_exists($_SERVER['DOCUMENT_ROOT'].$imgLink)) {
        echo $imgLink;
        }
        else {
         echo "/content/images/nophoto.gif";
        }

   }

        function checkTH($imgLink){

    if (file_exists($_SERVER['DOCUMENT_ROOT'].$imgLink)) {
        echo $imgLink;
        }
        else {
         echo "/images/noimage.gif";
        }

   }

function getIMGsize($img){


list($width, $height, $type, $attr) = getimagesize($_SERVER['DOCUMENT_ROOT'].$img);
echo "params='lightwindow_width=$width,lightwindow_height=$height'";

}


function  titleCase($string)  { 
        $len=strlen($string); 
        $i=0; 
        $last= ""; 
        $new= ""; 
        $string=strtoupper($string); 
        while  ($i<$len): 
                $char=substr($string,$i,1); 
                if  (ereg( "[A-Z]",$last)): 
                        $new.=strtolower($char); 
                else: 
                        $new.=strtoupper($char); 
                endif; 
                $last=$char; 
                $i++; 
        endwhile; 

        $new= str_replace("Led ","LED ",$new);
        $new= str_replace("Lcd ","LCD ",$new);

        return($new); 
}; 




?>

1 个答案:

答案 0 :(得分:0)

鉴于问题很可能是空白问题,没有什么是理想的。简单的答案就是将doctype放在自己的文件中,并在每个页面前加<?php include("../includes/doctype.php"); ?>。就像我说的那样,并不理想,但有一个像这样的网站,没有整洁的解决方案。

我假设config.php的包含在整个网站上并不一致。

编辑:config.php文件在打开<?php标记之前有空格。删除那个以及最后一个?>标签之后的任何标签,您应该没问题。如果这不起作用,下一步将是提供浏览器接收的输出的前几行或网站的URL。

最终编辑:这绝对是一个空白问题。您可以通过在应用程序页面上查看源来判断,它在DTD之前有一个空行。考虑重构页面以使用单个PHP标记而不是每行一个,如下所示:

<?php include("../includes/config.php");

// SEO TAGGING 
$pageTitleDisp="Page Title";
$pageKeywords="cars planes bikes";
$pageDesc="this is a webpage that looks pap in IE";
$canonical="http://mydomain.com/about/";
$popbox="true";

include("../includes/header.php"); ?>

没有充分的理由在每一行上都有单独的PHP标记。另请考虑从?>文件中删除结束config.php标记。