How to create the same Header and Footer on Separate web pages in PHP
In this tutorial, you will learn how to create a header and footer in PHP.
In each page, we have to write the same code for our header and footer, so in this tutorial, you will learn how to make global header and footer files.
- First, create a file named Index.php.
- Then create a file named header.php and footer.php.
- You have to include header and footer in the index file.
Code of index.php
1 2 3 4 5 6 7 8 9 10 11 |
<?php $title = "Php Header Footer"; include "header.php"; ?> <p><b>Visit T4Tutorials for more how to's and tutorials.</b></p> <p style='text-align: center;'> We are using two different files as header and footer. </p> <?php include "footer.php"; ?> |
Code of header.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<html> <head> <title
><?php echo $title; ?></title> <link rel="stylesheet" type="text/css" href="css.css"> <style type="text/css"> .header { width: 100%; height: 10%; background-color: lightgrey; } .footer { width: 100%; height: 10%; background-color: green; position: absolute; bottom: 0%; } </style> </head> <body> <div class="header"> <center><h1 style="color: black;">This is the header.</h1></center> </div> |
Code of footer.php
1 2 3 4 5 |
<div class="footer"> <center><h1 style="color: white;">This is the Footer.</h1></center> </div> </body> </html> |