Loading...
PHP

Include

This concept is used to include a PHP script in another PHP script the available functions are.,
1. include
2. include_once
3. required
4. required_once
If we include the external file connect php program we can access executable statements, functions process, exe from current web page.

  1. Include:
    By using this function we can include external file number of times in the current script if external space is not available it returns warning message and executes rest of statements.
    page1.php
    <?php
    echo “Welcome to Page 1”;
    include “page2.php”;
    echo $Sno;
    ?>
    page2.php
    <?php
    echo “Welcome to Page 2”;
    $Sno=100;
    ?>
    Output:
    Welcome to Page 1
    Welcome to Page 2
    100
  2. include_once:
    It is same as include but we cannot include the external page number of times.
    <?php
    include_once(“page2.php”);
    include “page2.php”;
    ?>
    Output:
    Welcome to Page 2
    Welcome to Page 2
  3. required:
    It is same as include but it returns a fatal error if external file is not available and stops execution of script.
    <?php
    require “page2.php”;
    echo “Hi”;
    ?>
  4. require_once:
    It is same as require but we can include external file only one time.
Leave a Reply

Your email address will not be published. Required fields are marked *