Library tutorials & articles
Simple PHP includes
- Introduction
- The Navigation Bar
- Conclusion
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.
Related articles
Related discussion
-
Create this kind of website
by maidentv (1 replies)
-
PHP London July Meetup
by webdeveloperit (1 replies)
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
SOFTWARE PHP WORK
by synctel (0 replies)
-
London PHP / MySQL Superstar needed!
by gatewaytechnolabs (1 replies)
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.
Try using this:
include $SERVER[DOCUMENTROOT]."/common/yourfile.php";
This should do it.
Breckenridge Guy!
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
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
Shizuka
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.
zidane,
your reply was so helpful, that i've built a site around it and registered just to thank you.
so... thank you.
fame
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!
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:
<?php
if(!empty($HTTPGETVARS[page]) and fileexists("./$HTTPGETVARS[page].inc")) {
include("./$HTTPGET_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.
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
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!
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!
This thread is for discussions of Simple PHP includes.