Pregunta

I'm trying to make a website, but when I try to validate at W3C, there are 2 errors happening:

 Line 28, Column 7: Stray end tag head.
</head>
Error Line 29, Column 6: An body start tag seen but an element of the same type was already open.
<body>

My code is:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="pt-br">
<!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>SpotBOT - Engenharia Mecânica Cotidiana</title>
<meta name="description" content="Página pessoal sobre enganharia mecânica, faculdade, dificuldades, trabalhos e realizações na área.">
<link rel="apple-touch-icon" href="/icon-iphone.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/icon-ipad.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/icon-iphone4.png" />
<meta name="viewport" content="width=device-width">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="../css/main.css">
<script src="../js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<script src="../WYSIWYG/ckeditor.js"></script>
<?php
include("db_connect.php");
if (!isset($_SESSION)) session_start("Spotbot");
if(isset($_GET['page'])) {$page = $_GET['page'];}else {$page = "index";}
$query_select=mysql_query("SELECT permissao FROM indexpage WHERE pagename = '$page'")or print (mysql_error());;
if (mysql_num_rows($query_select) == 0){$nivel_necessario = 1;}
while($linha = mysql_fetch_array($query_select)){$nivel_necessario = $linha['permissao'];}
if(!isset($_SESSION['UsuarioID'])){$_SESSION['UsuarioNivel'] = "1";}
if ($_SESSION['UsuarioNivel'] < $nivel_necessario) {
session_destroy();
header("Location: http://spotbot.in?page=permission"); exit;
}
?>
<script>
    window.onload = function() {
        CKEDITOR.replace( 'texto' );
    };
</script>
</head>
<body>
<?php include_once("analyticstracking.php") ?>
<!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]--> 

<!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->
<div lang="pt-br" class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a>
      <?php include("menu.php");?>
    </div>
  </div>
</div>
<div class="container" lang="pt-br"> 
  <!-- Main hero unit for a primary marketing message or call to action -->
  <div class="hero-unit">
    <?php
            if(isset($_GET['page'])) {$page = $_GET['page'];}
            else {$page = "index";}
            $query_select=mysql_query("SELECT * FROM indexpage WHERE pagename = '$page'")or print (mysql_error());;
            if (mysql_num_rows($query_select) >= 1){
            while($linha = mysql_fetch_array($query_select)){
            $title = utf8_encode($linha["title"]);
            $text = utf8_encode($linha["text"]);
            $link= utf8_encode($linha["link"]);
            $button= utf8_encode($linha["button"]);
            }
                echo "<h2>$title</h2>
                <div id='post-data'><p>$text<br/></p></div>";
                if ($button != ""){echo "<p><a href='$link' class='btn btn-primary btn-large'>$button &raquo;</a></p>";}
                echo "</div><!-- Example row of columns --><div class='row'>";
            $query_select=mysql_query("SELECT * FROM indexfooter WHERE pagename = '$page'")or print (mysql_error());;
            while($linha = mysql_fetch_array($query_select)){
            $title = utf8_encode($linha["title"]);
            $text = utf8_encode($linha["text"]);
            $link= utf8_encode($linha["link"]);
            $button= utf8_encode($linha["button"]);
            echo "<div class='span4'><h3>$title</h3>
                <p>$text<br/>";
                if ($button != ""){echo "<p><a href='$link' class='btn'>$button &raquo;</a></p>";}
                echo "</div>";
            }}
            else
            {
                echo "
                <h2>Página não encontrada</h2>
                <p>A página que você procura não existe ou foi deletada.<br/>
                <p><a href='http://spotbot.in' class='btn'>Voltar à pagina principal &raquo;</a></p></div>
                </div><!-- Example row of columns --><div class='row'>";
            }
            ?>
  </div>
  <hr>
  <footer>
    <div id="geral">
    <p><a href="https://plus.google.com/107266754114799149959?rel=author">Me encontre no Google +</a></p>
    <p>Spotbot&copy;  2013</p>
    <p>All rights reserved.</p>    </div>
  </footer>
</div>
<!-- /container --> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="../js/vendor/jquery-1.8.3.min.js"><\/script>')</script> 
<script src="../js/vendor/bootstrap.min.js"></script> 
<script src="../js/plugins.js"></script> 
<script src="../js/main.js"></script> 
</body>
</html>

Just edited with the full code.

I'm trying to find the error, but I cant find it.

Please, help me find this bug ;)

¿Fue útil?

Solución

In the actual HTML code generated, which you kindly uploaded for inspection, line 23 begins with U+FEFF ZERO WIDTH NO-BREAK SPACE. It is an invisible control character, which is completely valid as such in HTML, but it is taken as a data character. No data characters except whitespace (and U+FEFF is by definition not whitespace in HTML) are allowed between elements in the head part. This means that any data character there (whether U+FEFF or FOOBAR) implicitly closes the head element and opens a body element (where data characters are allowed). This explains the error messages.

U+FEFF is the same character as the Byte Order Mark (BOM). Apparently, a .php file has been saved in UTF-8 format with BOM at the very start. Although BOM is perfectly legal (and often useful) at the start of a UTF-8 datastream, it has a different meaning (as a data character) anywhere else. PHP processors fail to remove the BOM when they insert the content of a .php file.

So the problem should be fixed by opening the db_connect.php file in an editor and saving it in UTF-8 format without BOM.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top