PHP Includes - Talking HTML
PHP includes are a vital aspect of websites and should be incorporated into every Web Developer's workflow.
Code via Chris Coyier and the CSS Tricks website
Main reason for using a PHP include:
All code for a specific function is under 1 roof.
If you need to make a change you change it in 1 spot instead of going to each and every individual page
When using and creating includes the files need to have the php extension on the file.
Index.html turns into index.php
Popular includes to create:
Footer.php
Header.php
Navigation.php
Other examples:
Meta data/ stylesheets/ head information
Social media
Separate website tracking code if you don’t/can’t include it in the footer.
General include statement:
PHP include statement from root.
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/common/header.php";
include_once($path);
?>
DISCLAIMER: when using PHP includes you HAVE TO ensure ALL OF YOUR LINKS are sourced from the root.
All internal navigation
Direct links from 1 page t
Comments