homepage Welcome to WebmasterWorld Guest from 107.22.78.233
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Is there any downside to having one page do it all?
PHP question
HughMungus




msg:1292955
 11:32 pm on May 6, 2004 (gmt 0)

If you have a database-driven website, is there any downside to having one "page" (php file) do everything? That is, if there are no arguments in the URL, it just displays the "home page"; if there are arguments in the URL (e.g., the name of a category), it displays a different "page" based on the arguments in the URL.

I can't think of any downside other than a single page that's somewhat complex.

Comments?

 

uncle_bob




msg:1292956
 11:39 pm on May 6, 2004 (gmt 0)

I think you have answered your own question. The main downside is that it is complex, this means more bugs and worse performance. If you feel the code is too big to sensibly manage, then you know it is time to break the page up. Also if broken up, you can use include files for common functions you use so you start being able to structure and reuse your code better.

jamesa




msg:1292957
 12:12 am on May 7, 2004 (gmt 0)

Manageability is the only issue I can think of.

In a db driven site, if the format of the page is identical - where the only thing that changes is the db inserted content - then one page is the way to go. One page of code to manage regardless of the number of content pages it produces.

But if you have content imbedded in the code, like:

if ($page == '') { echo "blah blah"; } elseif ($page == 'about') { echo 'bleh bleh bleh'; } etc...

...then separate pages are easier to manage in my experience. When I'm editing pages I like to look at as little of the surrounding HTML/PHP as possible.

httpwebwitch




msg:1292958
 2:43 pm on May 7, 2004 (gmt 0)

You might want to use real sensible URLs with real names, so people can bookmark them and write them on cocktail napkins, and when you want to direct someone by phone you're not explaining all about the question mark thing.

"yes - it's index dot p-h-p, then a Question mark, pg, equals sign... "

Aside from that kind of argument, there's no reason not to do what you describe. A lot can be done with htaccess mapping and redirects.

There are common sense limits. If your page looks like:

if ($HTTP_GET_VARS['pg']=='contactme'){
// 6 pages of HTML
} elseif ($HTTP_GET_VARS['pg']=='mystuff'){
// 6 more pages of HTML
} elseif ($HTTP_GET_VARS['pg']=='things'){
// 10 pages of HTML
} elseif ($HTTP_GET_VARS['pg']=='work'){
...

then parsing your code might get a little slow. Though the disadvantages are negligible, I don't see any advantages, either.

seomike2003




msg:1292959
 7:14 pm on May 7, 2004 (gmt 0)

If it isn't very big you can use a mod rewrite and make the site look like it's got 100's of pages.

These forums do something similar.

webmasterworld.com/forum88/3741.htm

/forum88/ is php related
/fourm89/ is ad sense

point is that it's all coming from 1 page probably named forum.php or what have you. Bretts just re writing the string from something like this forum.php?cat=88 to forum88/

so one page is now 1000's of different pages.

HughMungus




msg:1292960
 7:49 pm on May 7, 2004 (gmt 0)

You might want to use real sensible URLs with real names, so people can bookmark them and write them on cocktail napkins, and when you want to direct someone by phone you're not explaining all about the question mark thing.

Yeah, I've been thinking about this, too. What I need to learn next is how to make my links look like easy-to-read subcategories (e.g., widgets.com/redwidgets/smallredwidgets/ instead of widgets.com?c1=redwidgets&c2=smallredwidgets) without actually having those subdirectories and with the URL in the browser look like /redwidgets/smallredwidgets/.

HughMungus




msg:1292961
 7:52 pm on May 7, 2004 (gmt 0)

If it isn't very big you can use a mod rewrite and make the site look like it's got 100's of pages.

Yeah. But how hard is it to return a URL in the address bar that looks like /subcategory/subcategory/ instead of?s1=subcategory1&s2=subcategory2?

seomike2003




msg:1292962
 8:22 pm on May 7, 2004 (gmt 0)

not hard at all. I've mod rewritten a site that passed 4-5 variables.

It's about 3 lines of code in your .htaccess file that's it.

paybacksa




msg:1292963
 8:48 pm on May 7, 2004 (gmt 0)

I did one site as a single page, and ended up very unhappy with it because I always had to work extra hard to make every change fit into that model.

I know it seems natural (need another page, just have it generate another page) but the actual fact was that at times I wanted to generate a page right off the bat for a specific purpose, but ended up generalizing it to fit it into the template, finding where the general dynamic template didn't really scale well, fixing that, etc....

All statics is clearly not ideal, but I think all dynamic is also non-ideal.

A curent site under development uses my own version of a templating system, where the main page generates subpages, which then generate the content on the fly. This way I have a handful of coded pages which generate the hundreds of pages making up the site. The handful is varied enough to handle all of my needs, and if necessary I easily make one more following the same design.

Basically I abstracted with a layer between content and index.html, and so far it works very well. Nice set of include files, and very little redundant code. I am consciously avoiding further automating those (even though it seems so cool to do that) because I don't need to....

ergophobe




msg:1292964
 10:17 pm on May 7, 2004 (gmt 0)

One solution to paybacksa's problem is this:

- use mod_rewrite to send everything to index.php.
- check the url. Is this a valid address for a file? If so, just show that file
- if not, generate the dynamic page with the default template.

Solution two
- each dynamic page has information (either in the db or as a file header or whatever) that says which template to use and have 2-3 templates.

paybacksa




msg:1292965
 1:33 am on May 8, 2004 (gmt 0)

- check the url. Is this a valid address for a file? If so, just show that file

This requires knowledge of valid file names, which means you need a table of all valid files.

That was the solution I ended up with, but I used a custom4040 handler to do the page generation when the file was supposed to be there but wasn't. Clear the directory to auto re-generate the files at next request. Works like a charm, but I feel lucky I'm not doing much maintenance on that site.

moltar




msg:1292966
 3:02 am on May 8, 2004 (gmt 0)

You can check for existing files with the following code:

RewriteCond /path/to/home%{REQUEST_FILENAME} !-d
RewriteCond /path/to/home%{REQUEST_FILENAME} !-f

ergophobe




msg:1292967
 2:32 pm on May 8, 2004 (gmt 0)

or with

if (file_exists($file)) {
header("Location: $file");
exit;
}

mep00




msg:1292968
 8:58 am on May 9, 2004 (gmt 0)

The complexity issue is easy to address: the one file should only do user auth., general house keeping, and then determin which files and/or templates to include. In this way, on the one hand, every thing is centrally orginized, and on the other hand, the details are distributed. It's the best of both worlds.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved