include and require in php
snippet in php

include and require in php

user2074

// Include a file, if it can't be found: continue.
<?php
include 'mainfile.php';
?>
  
// Alternatively: Require a file to be imported or quit if it can't be found
<?php
 require 'requiredfile.php';
?>

require in php

user8914

// Require a file to be imported or quit if it can't be found
<?php
 require 'requiredfile.php';
?>

php includes

user3368

#Includes and requires Statements

#Includes and requires hlep you save time when it comes to changing small
 # aspects of otherwise identical pages. 
#Requires stop the script if there is something missing that is
 # require d in the place of where the inlcude statement is. 
#You can also have it be requiired once

#Example 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Your web site</title>
 </head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <body>
    <ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="about.php">About</a></li>
        <li><a href="contact.php">Contact</a></li>
    </ul>
    <h1>Home</h1>

 <?php 
 echo '<p>Your website -- under construction!</p>'
 ?> 

 <footer>
    <p>
        Your Website © 2019
    </p>
 </footer>
 </body>
</html>
=================

becomes::

<?php include 'inc/header.php'; ?>

    <h1> Home</h1>

 <?php 
 echo '<p>Your Website -- under construction!</p>'
 ?> 
 <?php include 'inc/footer.php'; ?>