php require
snippet in php

include and require in php

user10000

// 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

user8784

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

php require

user4696

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

php includes

user7118

#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'; ?>

echo require php

user3965


return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>

//$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return within the included file while the other does not. If the file can't be included, false is returned and E_WARNING is issued.