How do I include one file in another with PHP?

This is my favorite approach to including one file in another, but it means your server has to be running PHP and all of your file names need to be named .php instead of .html. If you’re not sure if your web hosting runs PHP you’ll have to check with them otherwise you can follow these instructions to see if it works.

<?php
     include("includes/header.php");
?>

Create a directory called includes and put all the files you would want to include in there. Make sure the file calling the include is a .php extension. In order to see php on your local machine you’ll have to have PHP running on your web server, you can use MAMP for this.

Back to Blog

Say Hello

You can reach me by email, I'd love to hear from you.