I've been wondering about how my site is setup lately. I haven't found many other sites that use a site structure like mine, so I'm kind of wondering if there are any disadvantages to the way my site is setup.
When you browse my site at http://www.supercarcentral.com, a visitor uses the same page the entire time. This page is called index.php and depending on variables passed through the url(like this: http://www.supercarcentral.com/index...in&carselect=z) and through forms, the page uses the require() or include() functions to include the correct file for the page based on the variable "action" in the url. Also, page names are determined by the action variable. A connection to the mySQL database is made only once, and it's made on index.php, so that the included connections don't have to have mysql_connect in them.
There are many advantages to this structure, one of them being that I only have to update one file when I want to change the entire design for the site. I also don't have as many big php files on the server.
I'm wondering if you guys know of any disadvantages of having my site setup like this.
There aren't really any disadvantages to this one - all sites should be moving towards the 100% dynamic model.
There's no reason to do it any other way anymore.
Your approach is very similar to the fusebox web application architecture methodology (for cold fusion) http://www.fusebox.org/
If you think it would make the code more managable, you can break it down further so that different php scripts handle the different major sections of the site - just like breaking down a site accross directories may be used to help keep a site organised and manageable.
Also, your design lends itself easily to using one of the search engine friendly hacks that get discussed often here.
Dynamically including logic code from PHP files based on the action supplied to your script is a really interesting idea - I'm surprised I've not seen it done before. I don't see any problems with that (as long as you make sure the action parameter is filtered to prevent people using it so access your file system, and you make sure if an invalid action is specified it dies gracefully).
Combining it with a search engine URL friendly technique (see this thread: http://www.sitepointforums.com/showt...threadid=15798 ) would be easy as well.
In fact... I'm very tempted to use this in my next project - the fact that a basic index.php is used for everything makes it really easy to include code that needs to be on all pages of the site like session management, templating etc.
Thanks for the tip :)
I've never really considered using a search engine URL friendly technique before. That sounds like a very good idea. I'll try to implement that soon. Also, thanks for your comments. I appreciate them.