Page 1 of 2
index.php?somevar=somepage linking
Posted: Mon Jul 18, 2005 3:22 am
by Ree
i asked a similar question in another thread, but that one had another question initially so i decided to re-ask here.
having in mind that a site has a fixed number of pages of a similar layout (with different content of course), is //index.php?somevar=somepage kind of linking acceptable? if i use //somepage.php linking, i save one function (which is used to include 'somepage' based on $somevar value if using query string) and the link looks 'cleaner', but i get quite a bit of repetitive identical layout code on each somepage.php as well as additional files (to store ONLY the content code for the sake of my own convenience, each of them included in a corresponding somepage.php). in my previous thread i was explained that it's a bad design to use query strings for static stuff which seems logical. however, there are lots of tutorials explaining how to use query strings for simple static page navigation on the net (even zend.com has one). do you find this kind of linking normal for accessing static content? do you use it? why/why not? opinions and explanations are very welcome.
Posted: Mon Jul 18, 2005 3:33 am
by s.dot
I don't usually use query strings for static navigation. I mean, it doesn't hurt anything... but if you can avoid it, why would you?
There's an exception though that I use. I have a 'fun' page which has different sections, games, puzzles, adlibs, videos, pictures, etc. I use a query string to determine the section. That's about it though.
I would exactly say it's bad practice as it can get you familiar with using query strings and using $_GET. But I avoid it whenever possible.
Posted: Mon Jul 18, 2005 8:24 am
by shiznatix
i use the index.php?u=page when i am kinda useing a iframe but without the iframe. it works just fine if you do a little bit of security first. i have heard many people bash it but i dont understand why, it saves time by not having to edit a billion different pages over a simple design change and its easy to manage plus the code is usually seperated because the index.php page is mostly html and the included pages are your code so it makes life that much easier.
Posted: Mon Jul 18, 2005 8:50 am
by nielsene
It may sound like I'm splitting hairs here, but...
I personally detest somepage.php?page=foo, but I like somepage/foo, where somepage is a PHP script (using a ForceType directive in Apache).
You often see this style on sites that do like
Code: Select all
http://domain/articles/Design/CoolDesign
http://domain/articles/CoolScripts/FooiliciousScript
etc.
The "Design" and "CoolScripts" directory may not really exist, and their faking it via the ForceType and "look-back" chaining. Once they find the "articles" script, it explodes the following "directories" and then uses those to setup the needed variables, in that sense its exactly like ?area=onething&article=foo query string, but doesn't look at ugly

. It also seperates true query string behavoir from "navigation"/"filesystem abstraction" uses.
Posted: Mon Jul 18, 2005 9:10 am
by John Cartwright
On every single one of my pages I probably use an index which loads pages depending on the query string. I greatly benefit from this as I can control which users, depending on their user priviliges/permissions, can view which page -- and just as easily restrict pages. The list goes on and on, and I know this is all possible through other methods, I just find it seemingly easier to control things when they are all funnelled through 1 spot (index).
Posted: Mon Jul 18, 2005 9:16 am
by nielsene
I tend to "funnel" everything thought my "master include"
ie every script starts
Code: Select all
require_once("include_others.inc");
include_others.inc does permissions checks, logging, some minor URL parsing to determine which block of other classes to include, etc.
Everything stills goes through one place, but its not overloading a single page. (It also plays nicer with most off-the-shelf apache-log stats packages.)
Posted: Thu Jul 21, 2005 9:13 pm
by josh
I find if I am going to include a file based on a query string, I use mod_rewrite, it [the url] looks much more "friendly" to the end user which I think is more important then how easy it is for the developer, the easier it is for some one to remember or type your url, the more likely that user is to re-visit that page, or spread your web site via word of mouth.
Posted: Tue Sep 27, 2005 9:31 am
by psatish
Hi All
I am a newbie to PHP and have just started out on a large project. It has a demo version that has the index.php?page=somepage format.
I read the earlier posts but am still not clear if it is definitely a good idea to do this instead of using a direct link to the desired page.
Could somebody help me and explain which to follow?
Thanks and Regards
Posted: Tue Sep 27, 2005 10:03 am
by Jenk
I normally just make a page for each script and include a header file and footer file, but I'm starting to realise the benefits of doing it the other way round.
The main 'bonus' I can see to using index.php?pid=foo is you can have all the other pages with whatever extension you like and can then restrict all users to only be able to view .php extensions, thus forcing them to use index.php

Posted: Tue Sep 27, 2005 10:57 am
by s.dot
Jenk wrote:I normally just make a page for each script and include a header file and footer file
ditto
Posted: Tue Sep 27, 2005 11:22 am
by psatish
Thanks for your replies. But what can one do if we want to pass querystrings? I have page where I am passing as
What do I do then?
Thanks and Regards
Posted: Tue Sep 27, 2005 11:36 am
by alvinphp
On my site I have one main page that is loaded every time (index.php). Depending on what is passed the appropriate includes are loaded (which I have tons of). As this is all done in a OOP style where I seperate presentation, function, and data making the site very structured. As I have been building on this site for almost a year (it is modular so I keep adding to it) the is getting quite large, yet it is very easy for me to add an additional module and change existing ones without effecting other parts of the site. And if I have to change the style of the site I can do it in one place and it automatically changes the entire site.
So, for my structure, I do use the querystring to load static content and for searches.
Posted: Fri Sep 30, 2005 9:59 am
by pilau
In my website, I use an Iframe
I thought of changing it to querystring but CBA

Re: index.php?somevar=somepage linking
Posted: Fri Sep 30, 2005 11:14 am
by Christopher
Ree wrote: if i use //somepage.php linking, i save one function (which is used to include 'somepage' based on $somevar value if using query string) and the link looks 'cleaner', but i get quite a bit of repetitive identical layout code on each somepage.php as well as additional files (to store ONLY the content code for the sake of my own convenience, each of them included in a corresponding somepage.php).
This is the problem that is solved by the Front Controller pattern, which is just a script that takes URL request with parameters like you specify and selects the appropriate response for it.
Ree wrote:in my previous thread i was explained that it's a bad design to use query strings for static stuff which seems logical. however, there are lots of tutorials explaining how to use query strings for simple static page navigation on the net (even zend.com has one). do you find this kind of linking normal for accessing static content? do you use it? why/why not? opinions and explanations are very welcome.
I don't see why it is bad design to "use query strings for static stuff"? However it may be bad design to have duplicated code for the reason that you need to make changes to every duplicate. You may want to read about DRY (
http://www.artima.com/intv/dry.html) to find out more about this design concept.
Posted: Fri Sep 30, 2005 12:41 pm
by psatish
I have implemented the same after reading all the discussions. So now all my pages are channelled through index.php with a querystring showing what page to be loaded.
But I think my application design has to be more tightly OOP-ed to take advantage of such designs.
Thanks and Regards