PHP - Includes

Code provided here is for anyone to re-use, no attribution neccesary.

Screenshot of css code
Technologies
HTML PHP

Description

PHP can allow you to re-use code from php files, which provides you with a great way to template your sites. This can reduce your time administering the site, especially when dealing with code that is reused across multiple pages.

How it works

PHP has a function called 'include' that allows you to include files in other files. This enables you to have a light touch content management system without needed a full CMS or a database.

This trick can also be used to include other files, like functions, data and configuration files. Let me know how you use include files in your projects.

The below code shows you how it works. The below files will generate a base for building a site just like this one.

header.php
<?php
    // PHP file for the header
    $pageName = 'Index Page';
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title><?=$pageName?></title>
    </head>
    <body>
                            
footer.php
        <div class="footer">
            <p>©<?php echo Date('Y'); ?> Copyright Your Name</p>
        </div>
    </body>
</html>
                            
index.php
<?php
    // PHP file for the index page
    $pageName = 'Index Page';
    include('header.php');
?>            
            <div>
            <h1>Page title here</h1>
            <p>Some text here</p>
            </div>
<?php
    include('footer.php');
?>   
                            

More information

For more information on some of the techniques used in this project please see the following documents on the memopad pages.


Photo credits

development screen

Photo by Zany Jadraque on

Unsplash
development screen

Photo by Álvaro Bernal on

Unsplash
development screen

Photo by Taylor Vick on

Unsplash
training session

Photo by Campaign Creators on

Unsplash
training session

Photo by JJ Ying on

Unsplash
training session

Photo by Tobias van Schneider on

Unsplash
training session

Photo by Martin Woortman on

Unsplash
training session

Photo by Russ Ward on

Unsplash