View Full Version : questions on remote php source files (include)

12-13-2010, 11:08 PM
A little while ago, the nice helpful people here on cf told me about

<?php include $_SERVER['DOCUMENT_ROOT'] . '/footer.php'; ?>

And I've used it sparingly, pretty much just for my page header (banner, menu links) and footer.

Some questions I have though, are where should I begin and where should I stop?
Are there any things that won't function correctly if aren't on the actual index.php file?
Could I put the meta tags and things inside a remote php file? Would it cause problems if I even put the <html> opening tag into the remote php file?

Right now my codes a little messy, so I'm trying to 'clean as I go', and keep things organized, so it won't be as hard to go back and tidy things up when I have the spare time :cool:

Are there any down sides to having multiple remote files?
(side column in one, header in one, footer in one)
Or is it better to have all of the data in 1 file?

12-13-2010, 11:33 PM
There is no drawback at all to having different slices of your HTML code in different PHP files that are included into the main file. In fact, this is exactly how CMS systems work. If you get curious, open up a copy of Wordpress some day and take a look.

Feel free to chop up your page into as many sections as you want. When you put it all together with includes the end user won't have any clue of how it got there and it will work as you intended.

You could theoretically put every single character of the page's HTML into different files and included them one-by-one into your index.php page and it wouldn't hurt a thing.

12-13-2010, 11:53 PM
Thanks :)

Sounds like a fun idea lol.

12-14-2010, 05:55 AM
If you really want to see how efficient it can be to chop up pages into multiple files checkout the Model View Controller (MVC) setup. Its much more sophisticated than simply calling in your header and footer files on each page manually. The MVC will make your site truely dynamic and easy to update in the future.

Basically it starts with the controller (a switch statment) that reads the current url and changes the files to be included into the page based on the url. Its really not that bad to understand, just watch some video tutorials on developing one and you should get it.

Also the MVC is the perfect place to get rid of that tacky .php or.html ending on your url. In fact you can get that url to spit out basically whatever you want it to regardless of the file names being called.

12-14-2010, 10:29 PM
standard method for assembling php pages;
index.php in root

create a plugins folder ....

include the pages with this code

<?php include 'plugin/plugin_pages.php;' ?>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum