Library tutorials & articles

Simple PHP includes

Introduction

Nobody likes frames. But if you're not using frames, you have to update every page of your site every time you modify your menu. Don't you wish there was another way? Well, there is. Simple PHP includes allow you to create a professional, frameless site without too much work. Want to learn how? Read on...

PHP includes are very simple and really practical. How they are used is they allow you to use one line of code in every page that you want your menu on in place of say 30 - 50. Also, you never have to edit this code once it's there, you can just edit your menu file. They work by taking all the content of a file and putting it into the file being viewed at the location where the INCLUDE tag is.

Comments

  1. 05 Sep 2004 at 21:02

    Try using this:


    include $SERVER[DOCUMENTROOT]."/common/yourfile.php";


    This should do it.


    Breckenridge Guy!

  2. 03 Sep 2004 at 17:53

    email me , a your instructions as follows  just gives you a name for the first page when creating your example for the first half of the code but what about the second half of the code with the other half of the table what do you name it and on the third part of the code you dont say what to name it either, i am a newbie and and reading your instructions for this example loses me real quick cause you leave most of it out this intruction and wher to put or use the link in php??? im lost for a newbie can u give plain er instructions please php for dummies, lol

  3. 12 Sep 2003 at 16:19

    I gave the "corrected" code a try, but I'm using Javascript rollovers in the menu bar and now the buttons pause before loading, even though the script preloads them--and not only that, but it does that for every "page" in the site.




    Is there any way to check for cached versions of my preloaded buttons so it doesn't have to load them fresh for every page?  Maybe some kind of If-Then-Else instead of using the

    Code:
    <? include("menu.inc") ?>
    ???


    Shizuka

  4. 10 Jul 2003 at 19:50

    If security is not an issue, what is wrong with simply making you header, footer, sidebar content as .txt includes for example and just use the <?php ;?> where you want them to show up in your .php files that contain main content?
    Also, where can I go to learn how to manage the whole site with PHP? I find a lot of stuff is either too hard to understand or doesn't explain all the terms it uses.

  5. 09 Apr 2003 at 11:24

    zidane,


    your reply was so helpful, that i've built a site around it and registered just to thank you.


    so... thank you.  




    fame

  6. 29 Mar 2003 at 15:36

    Quote:
    [1]Posted by Zidane-Tribal on 8 Mar 2003 03:10 PM[/1]
    The include will be main.inc if the variable page is not defined. Now, you can make all your content with a .inc extension and include it with the one page that has this code. For links, use http://yoursite/index.php?page=NameOfPage.inc


    There you go.



    FYI, I thought the original tutorial was helpful but what Zidane added is certainly more practical (eventhough his tone was unnessecary).  Anyway, slight correction.  To reference the pages, you would use http://yoursite.index.php?page=NameOfPage   (no need for the .inc).


    Enjoy!

  7. 08 Mar 2003 at 15:10

    Oh, yeah, what a great tutorial - not! There's no security whatsoever and its capability is low. So, if you're smart (Not to mention a master PHP coder Hint Hint), use the following:


    Code:

    <?php
       if(!empty($HTTPGETVARS[page]) and fileexists("./$HTTPGETVARS[page].inc")) {
           include("./$HTTP
    GET_VARS[page].inc");
       } else {
           include("./main.inc");
       }
    ?>


    The include will be main.inc if the variable page is not defined. Now, you can make all your content with a .inc extension and include it with the one page that has this code. For links, use http://yoursite/index.php?page=NameOfPage.inc


    There you go.

  8. 22 Jan 2003 at 14:36

    I discovered that the virtual root of my Web account was different from what I thought it was.


    The root starts several directories below where I thought it started.


    I'm new to the particular hosting service where my site is!


    Thanks again.


    Liz


  9. 22 Jan 2003 at 11:41

    I'm new to PHP and would like to use virtual paths for my PHP includes like I do in ASP:


    <!--#include virtual="/common/myinclude.asp"-->


    I've tried:


    <$ include ("/common/myinclude.php") ?>


    I get an error message "Unexpected T_INCLUDE at line 3..."


    Thanks!


    Liz
    PS Your tutorial is well written. You'll have a book contract before long!

  10. 18 Jan 2003 at 04:46

    Hi!


    Thanks for the great tutorial! It really helped me a lot.
    One question still:
    If i want include more than 1 (txt)file with just 1 link, (for instance text1.txt in tablecell A, and text2.txt in Table cell B, and perhaps a picture in Table cell C) how do i put that in the hyperlink?


    Hope you can help me out on this one.


    Thanks again!

  11. 01 Jan 1999 at 00:00

    This thread is for discussions of Simple PHP includes.

Leave a comment

Sign in or Join us (it's free).

Jamie Lindgren Uhm... I dunno why I'm typing this, cuz nobody is gonna read it probably, but anyway... I am (guess my age!! haha... 14) years old and I like programming, web design, and graphic design. I'm pursui...

Related discussion

Related podcasts

  • EarthClassMail.com - Moving from LAMP to .NET 3.5

    Scott chats with Matt Davis, architect at EarthClassMail.com, about their move from a LAMP stack (Linux/Apache/mysql/PHP) to .NET 3.5. What's working, what's not, and what kinds of issues are they running into as their architect their solution.

Events coming up

  • Dec 3

    The Auckland PHP December meetup

    Auckland, New Zealand

    Topic: Magento E-Commerce platform Speaker: Robert Popovic, LERO9, Robert is the Technical Director and co-founder of LERO9. Robert attended the Electrotechnical Faculty at The University of Belgrade where he graduated with a Masters in Computer Science and Information Technology. Robert has worked exclusively in the field of web and software development throughout his career.

Want to stay in touch with what's going on? Follow us on twitter!