![Page 1: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/1.jpg)
PHP INCLUDESFOR MODULARIZATIONCIT 230 – WEB FRONT-END DEVELOPMENT
![Page 2: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/2.jpg)
WHAT IS MODULARIZATION?
• Modularization is the idea of
separating a website into modules.
• A module can be a section that
repeats itself across a website.
• Example: Website headers and
website footers can be modules.
They are usually the same
throughout an entire website.
Website Body
Header
Footer
![Page 3: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/3.jpg)
WHY USE MODULARIZATION?
• Imagine a 250-page website that needs an update in the footer.
• With html only, you’d have to edit every single page, which would be a
very tedious and error-prone task (even with copy/paste).
• It saves time, money, and is easy to maintain.
• It can be done with a PHP include.
![Page 4: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/4.jpg)
WHAT IS A PHP INCLUDE?
• PHP is a scripting language used for web development.
• include is a command in the PHP language.
• It tells PHP to “include” a file.
• This is how a website can be modularized.
![Page 5: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/5.jpg)
SYNTAX OF PHP INCLUDE STATEMENT
• The syntax is composed of 5 elements
1. The opening PHP tag: <?php
2. The include command itself: include
3. The file path and name in quotes: ’/modules/footer.php’
4. A semi-colon to end the PHP statement: ;
5. The closing PHP tag: ?>
• The result: <?php include ’/modules/footer.php’; ?>
![Page 6: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/6.jpg)
WHERE TO INCLUDE THIS PHP INCLUDE?
• The include statement can go right in the html code.
• This is part of the file path. It tells the server to start at the root.
• Without this segment, the path would look something like this instead:
![Page 7: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/7.jpg)
FILE STRUCTURE
• With PHP include, you only need
1 file per module.
• A suggestion is to keep them
organized into a module folder.
• Example: footer.php can be
designated to be the only footer
file across the entire website.
![Page 8: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/8.jpg)
WHAT IS INSIDE THE MODULE FILE?
• The actual code that will be inserted!
• It is not an html file, so <!DOCTYPE>,
<html>, etc. are not needed.
• Think of it as a snippet of code that is
going to be inserted into a real html
file (the one with the php include).
![Page 9: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/9.jpg)
EXAMPLE: BEFORE PHP INCLUDE
![Page 10: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/10.jpg)
EXAMPLE: AFTER PHP INCLUDE
![Page 11: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/11.jpg)
WHAT ABOUT THE PAGE SOURCE?
• Assuming the web host
supports PHP, visitors will
not see the php code in
the page source.
PHP leaves no evidence!
![Page 12: PHP INCLUDES FOR MODULARIZATION CIT 230 – WEB FRONT-END DEVELOPMENT](https://reader035.vdocuments.mx/reader035/viewer/2022062309/56649e7d5503460f94b8094e/html5/thumbnails/12.jpg)
RESOURCES
• From PHP itself:
http://php.net/manual/en/function.include.php
• YouTube video on using PHP includes to modularize a website:
https://www.youtube.com/watch?v=R7k1K7UMs50
THANK YOU