include() messing up HTML structure

2019-09-14 21:22发布

I have a little problem. I have header.php and footer.php files which I include in every page. In the header.php I have the <head> tag with the scripts/styles and a div which is the top bar. In the footer.php I have closing tags.

 <?php include('header.php'); ?>
    <div class="content">
       <!-- CONTENT -->
    </div>
 <?php include('footer.php'); ?>

The problem is when I structure a page like the code above, my code is messed up, here is a picture http://img13.imageshack.us/img13/9640/92571581.jpg As you can see, the whole head seaction goes inside body. If I copy paste the code from header.php and footer.php without including, everything works as it should, picture here http://img833.imageshack.us/img833/2603/98557724.jpg

What is the problem ? Every tag is opened and closed in the right place.

Thank you

1条回答
何必那么认真
2楼-- · 2019-09-14 21:52

When you open a html page it loads automatically the default head. Your php code is running after that loading. Try not to use that include.

查看更多
登录 后发表回答