Home > database >  How to dynamic insert the header and footer of mainpage.html on other pages?
How to dynamic insert the header and footer of mainpage.html on other pages?

Time:09-30

I looked for many examples of how to display the same header and footer from one page to others dynamically without having to repeat the same html code and style.

And unfortunately I couldn't find a clear example of doing this, I've seen that it's possible using PHP, but I haven't found any practical examples.

I will be very grateful if anyone can give me an example or an article about.

CodePudding user response:

you could use include() for php, you have the header in one page and your footer in other. header.php somthing like

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
</head>
<body>

footer.php

<footer>
  <p>Author: Hege Refsnes</p>
  <p><a href="mailto:[email protected]">[email protected]</a></p>
</footer>
</body>
</html>

every other page

<?php include(header.php);?>
<div>
your content...

</div>
<?php include(footer.php);?>

  • Related