Includes
require a file
require loads another PHP file. Failure is a fatal error.
<?php
// header.php
echo "<header>Free Computer Courses</header>\n";
// page.php
require __DIR__ . "/header.php";
echo "<main>Lesson</main>\n";
include vs require
include warns on failure; require stops. Use _once variants to avoid double loading.
require_once __DIR__ . "/helpers.php";
Use __DIR__
Build paths from the current file so includes work regardless of the working directory.
Include habits
- Keep shared layout pieces in separate files
- Do not include remote URLs
- Return values from included files only when intentional
- Composer autoloading later replaces many manual includes
Comments
One comment per signed-in account. Comments are saved with this page’s URL.