Follow us on...
Follow us on Twitter
Register
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Senior Member ciullaanthony's Avatar
    Join Date
    Jan 2012
    Location
    Arlington, Texas
    Posts
    103
    Feedback Score
    0

    Cool Include an External File

    Intro

    Have you ever wanted to shorten a page that you have made, or have you ever wanted to include that other document? Well here is your chance. PHP has a couple features like "require", "require_once", "include", & "include_once". And so now you can use them to your satisfaction after this tutorial.

    The Difference Between Include and Require

    There is a huge difference between including a file and requiring a file. When you include a file it still imports it like they all do, but if the file does not exist or some other error, then PHP will just skip over it and pop up and error where the file messed up at. But when require fells, it stops processing the file that you loaded and displays and error, unless you have errors off in which the user will get a blank page, or they will be directed to a error document. Here is a example of each type of include.

    Include
    Code:
    <?php
    include 'index.php';
    ?>
    Include_Once
    Code:
    <?php
    include_once 'index.php';
    ?>
    Require
    Code:
    <?php
    require 'index.php';
    ?>
    Require_Once
    Code:
    <?php
    require_once 'index.php';
    ?>
    It is your choice which one you want to use.
    Need Help? PM me for help.Thanks for visiting: http://www.webdevforum.com/

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Feedback Score
    0
    What all file extensions will this include work on?

  3. #3
    Senior Member ciullaanthony's Avatar
    Join Date
    Jan 2012
    Location
    Arlington, Texas
    Posts
    103
    Feedback Score
    0
    PHP is all that I know of.
    Need Help? PM me for help.Thanks for visiting: http://www.webdevforum.com/

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Feedback Score
    0
    Ok thank you.

  5. #5
    Member Noble Genius's Avatar
    Join Date
    Jan 2012
    Location
    Northeast, U.S.A
    Posts
    42
    Feedback Score
    0
    I've seen php includes being used a lot for website headers and footers. Some people find it as an easy way to keep it updated without updating multiple pages.
    http://h5network.com/ - Design & Coding Forums

  6. #6
    Senior Member ciullaanthony's Avatar
    Join Date
    Jan 2012
    Location
    Arlington, Texas
    Posts
    103
    Feedback Score
    0
    Ya, I use them a lot. Normally I define variable like
    Code:
    <php 
    $content = 'hi'; ?>
    And then I put them in a external file and include it in the main. How do you use them?
    Need Help? PM me for help.Thanks for visiting: http://www.webdevforum.com/

  7. #7
    Member Noble Genius's Avatar
    Join Date
    Jan 2012
    Location
    Northeast, U.S.A
    Posts
    42
    Feedback Score
    0
    I hope you don't mean exactly that. It would be a waste of time if you wanted to include " <php
    $content = 'hi'; ?> " . :P

    Personally, no, I haven't used php includes. But I've assisted people using it. And a friend keeps telling me how he's used it for his site's footer. As for me, I prefer the long way.
    http://h5network.com/ - Design & Coding Forums

  8. #8
    Senior Member ciullaanthony's Avatar
    Join Date
    Jan 2012
    Location
    Arlington, Texas
    Posts
    103
    Feedback Score
    0
    I use it for things like in templates.
    Need Help? PM me for help.Thanks for visiting: http://www.webdevforum.com/

  9. #9
    Member Noble Genius's Avatar
    Join Date
    Jan 2012
    Location
    Northeast, U.S.A
    Posts
    42
    Feedback Score
    0
    Quote Originally Posted by ciullaanthony View Post
    I use it for things like in templates.
    Interesting. I'm pretty sure you use it for the headers or footers?

    Well, the only down-side is that it doesn't look very professional if you view the source. :P
    http://h5network.com/ - Design & Coding Forums

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts