If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    St. Helens, England
    Member #
    11 times

    PHP Tutorial 6 - Including/Requiring

    This is a follow-up to my previous tutorial: PHP Tutorial 5 - Arrays. It's wise you should read the first tutorial before you come onto the next one.

    In PHP there's multiple ways to include other PHP files (and/or files of any type) into your page/source. For instance we have:

    • include();
    • include_once();
    • require();
    • require_once();

    If you notice we have two functions with two different names, "require();" and "include();", the differences of these two are the error checks.

    When require(); comes across an error the script will have a fatal error and stop. However when include comes across an error the script will continue.

    When the functions are concatenated with "_once" it's telling PHP that this file must only be added into the script one-time and if the script finds another include or require of the same file it'll kill the script and throw errors.

    For the sake of this tutorial we have a text file called "cranavvo.txt" in our PHP root folder(htdocs/wwwroot) with this piece of text:

    I can't believe this is an included file!
    And to include a file we'd type:

    PHP Code:

    I can't believe this is an included file!
    The other functions are done the same. As a experienced developer it's wise use should use "require_once();" as your main file include function as it's handy for errors and checking etc. Thanks for reading.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 07:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: