Warning: unlink(/home/adddocom/public_html/s2c/defaultlogic/yts/search/1/PHP_Programmingheaders_and_footers.json): No such file or directory in /home/adddocom/public_html/s2/lib/mpr.php on line 691
PHP Programming/headers and Footers Learning | PHP Programming/headers and Footers Facts and Resources | DefaultLogic For Business




Headers and Footers

Create the header and footer files:

Create a file called "header.php" and enter the html code that you'd like at the top of each page as follows:

<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>

<h1>Our Web Site</h1>
<!-- end header -->

Create a file called "footer.php" and enter the html code that you'd like at the bottom of each page as follows:

<!-- begin footer -->
<p>Web Site last changed on 1/1/2005.</p>
</body>
</html>

Now we will create a web page that uses these headers and footers. Create a file called "page.html" and enter the following html code.

<?php
$title = "Welcome";                   // (1) Set the title
include "header.php";                 // (2) Include the header
?>

<!-- begin page content -->
<p><b>Welcome to our web site.</b></p>
<p style='text-align: center;'>
We're using PHP to provide you with dynamic content
for a better web experience.
</p>
<!-- end page content -->

<?php
include "footer.php";                 // (3) Include the footer
?>


We set the title for the page using (1)
We then include the header page using (2)
And we include the footer page using (3)

The final page should look like this:

<html>
<head>
    <title>Welcome</title>
</head>
<body>

<h1>Our Web Site</h1>
<!-- end header -->

<!-- begin page content -->
<p><b>Welcome to our web site.</b></p>
<p style='text-align: center;'>
We're using PHP to provide you with dynamic content
for a better web experience.
</p>
<!-- end page content -->

<!-- begin footer -->
<p>Web Site last changed on 1/1/2005.</p>
</body>
</html>

Files included in this way act as if their text was inserted into the main document right at the include call. PHP then continues to process the inserted file, allowing the inserted file to access all previously defined variables and functions (so $title in header.php was replaced with the value set in page.html: "Welcome"). This can have unintended consequences if a file is included more than once. To learn how to correctly include files containing functions and classes, see PHP Include Files.


Return to PHP.


  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

PHP_Programming/headers_and_footers
 



 

Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.


Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us