Skip to content
Chapter 03 of 05 · 2 lessons · ~18 min

Building Pages With PHP

Share one header and footer across every page and learn how browsers send data to PHP with GET and POST.

YOUR PROGRESS0%
/ Lessons in this chapter
07
How to Include Header and Footer in PHP How to build a multi-page site where the header and footer live in one file each. Coming soon
08
PHP GET vs POST Explained How data travels from a form or URL to PHP, and how to choose between GET and POST. Coming soon

Chapter practice task

Task: Turn three HTML pages into a small PHP site with a shared header and footer

  1. Create index.php, services.php and contact.php.
  2. Move the shared top of the page into includes/header.php and the bottom into includes/footer.php.
  3. Pass a $pageTitle from each page so every page has its own <title>.
  4. Highlight the current page in the menu.
  5. Add a search box that sends ?q= with GET and shows the search term safely.

By the end of this chapter

  • You can split a page into reusable parts with include and require
  • You know how to give each page its own title and active menu link
  • You understand how GET and POST send data, and when to use each

Quick answers for this chapter

What’s the difference between include and require?

If the file is missing, include shows a warning and keeps going, while require stops the page with a fatal error. Use require for files the page can’t work without.

Is GET or POST more secure?

Neither encrypts anything (HTTPS does that). But GET puts data in the URL, history and logs, so use POST for anything private or anything that changes data.

Why use __DIR__ in include paths?

It always points to the folder of the current file, so includes keep working no matter which page loads them.