
PHP remains one of the most practical languages for building websites. It runs on almost every hosting provider, integrates easily with databases, and lets you mix logic with HTML in a straightforward way. While many tutorials stop at printing a simple message, real websites need reusable layouts, multiple pages, and forms that actually work. This project-based guide explains how to create a web page using PHP by building a small multi-page site with a shared template, dynamic page titles, an active navigation state, and a secure contact form. These patterns form the core of countless professional PHP websites.
How AAMAX.CO Delivers Reliable PHP Solutions
Small PHP projects are a great way to learn, but business-critical websites require secure coding, clean architecture, and long-term maintainability. AAMAX.CO is a full-service digital marketing company that offers web development, digital marketing, and SEO services worldwide. Their developers build fast, secure PHP websites and custom systems using modern frameworks and best practices. With their website development expertise, businesses get dependable sites that are easy to update and ready to scale.
Planning the Project Structure
A clear folder structure keeps your PHP project organized. Create a project folder containing an includes folder for shared components, an assets folder for CSS, JavaScript, and images, and individual page files such as index.php, about.php, and contact.php in the root. Inside includes, you will create header.php, footer.php, and optionally a config.php file for site-wide settings such as the site name and contact email.
Setting Up Your Environment
Install a local server stack such as XAMPP, MAMP, or Laragon, or use PHP's built-in server by navigating to your project folder in a terminal and starting it on a local port. Place your project in the appropriate directory and open it in your browser through localhost. Enable error reporting during development so you can see warnings and fix problems quickly, but disable error display on your live server for security.
Creating a Shared Header
The header file contains the opening HTML, head section, and navigation. Instead of hard-coding the page title, use a variable that each page sets before including the header. For example, each page can define a pageTitle variable, and the header outputs it inside the title element, escaped with htmlspecialchars. This simple technique gives every page a unique, SEO-friendly title while sharing the same template.
Highlighting the Active Navigation Link
Good navigation shows users where they are. In your header, you can determine the current file name using the basename function on the current script path. Then, for each navigation link, compare it to the current file and add an active class when they match. Adding aria-current set to page on the active link also improves accessibility by telling screen reader users which page they are viewing.
Creating a Shared Footer
The footer file contains your closing content, such as copyright text, social links, and script tags, followed by the closing body and html tags. You can use the date function to display the current year automatically in your copyright notice, so you never need to update it manually.
Building Individual Pages
Each page file follows the same pattern: set the page title variable, include the header, write the unique page content, and include the footer. Here is a simplified example of an about page:
<?php
$pageTitle = 'About Us';
require __DIR__ . '/includes/header.php';
?>
<main>
<h1>About Our Company</h1>
<p>We help clients build better websites.</p>
</main>
<?php require __DIR__ . '/includes/footer.php'; ?>Using require with the directory constant ensures files are loaded with reliable paths and that the page stops with an error if a critical template file is missing.
Building a Secure Contact Form
On contact.php, create an HTML form that submits to the same page using the POST method. At the top of the file, check whether the request method is POST. If so, read and trim the submitted name, email, and message values. Validate that each field is filled in and use the filter_var function with the email validation filter to check the address. Collect any errors in an array and display them above the form. If validation passes, send the message using the mail function or, preferably, a library such as PHPMailer configured with authenticated SMTP for reliable delivery.
Protecting Against Common Threats
Security should be built in from the start. Escape all output with htmlspecialchars to prevent cross-site scripting. Add a CSRF token to forms by generating a random value, storing it in the session, and checking it on submission. Use a honeypot field or a CAPTCHA to reduce spam. If you store submissions in a database, use PDO prepared statements to prevent SQL injection. Never trust user input, even when it appears harmless.
Adding Dynamic Content
Once your template system works, you can make pages more dynamic. Store services or team members in an array or database table, then loop through them to render cards. This approach makes it easy to add or update content without editing HTML in multiple places, and it prepares your project for a future admin panel.
Going Live
Choose hosting that supports a current PHP version, upload your files via SFTP or Git, configure your email settings, and test every page and form. Enable HTTPS, set appropriate file permissions, and keep regular backups of your files and database.
Conclusion
Learning how to create a web page using PHP becomes far more valuable when you apply real-world patterns. A shared header and footer, dynamic titles, active navigation, and a secure contact form give you a reusable foundation for any small website. Build on this structure with databases and frameworks as your skills grow, and always keep security and maintainability at the heart of your code.
