Chapter practice task
Task: Turn three HTML pages into a small PHP site with a shared header and footer
- Create
index.php,services.phpandcontact.php. - Move the shared top of the page into
includes/header.phpand the bottom intoincludes/footer.php. - Pass a
$pageTitlefrom each page so every page has its own<title>. - Highlight the current page in the menu.
- 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.