0

So im trying to import a header.php into my index.php file file but it just doesnt work.

index.php:

<?php
require "header.php";

 ?>

    <main>
      <p> online! </p>
      <p> offline! </p

    </main>


<?php require "footer.php"; ?>

header.php:

<!DOCTYPE html>
<html>
  <head>

  </head>

  <body>
    <header>


      <p> this should be on top</p>


    </header>

  </body>

</html>

Footer:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <p> This should be on the bottom </p>
</body>

</html>

when i open the project i will only see what is written in index without header or footer

0

2 Answers 2

1

Your code return invalid HTML, because DOCTPYE, html, head and body are defined twice.

Change header.php to:

<!DOCTYPE html>
<html>
  <head>
  </head>

  <body>
    <header>
      <p> this should be on top</p>
    </header>

  #-- not closing body and html

Change footer.php to:

<p> This should be on the bottom </p>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure the path to your header and footer is correct. Then try including it in your page like this

require(“header.php”);

//Your html code here

require(“footer.php”);

2 Comments

What do you mean by path? I got header, index and footer in a folder on my deskopt but i thought it should work like that if they are in the same folder. Also ive tried what you suggested but it still doesnt work :(
Are you developing on Local host?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.