index.php?somevar=somepage linking

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

index.php?somevar=somepage linking

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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).
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
psatish
Forum Newbie
Posts: 7
Joined: Tue Sep 27, 2005 6:34 am
Location: Hyderabad, India
Contact:

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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

:)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Jenk wrote:I normally just make a page for each script and include a header file and footer file
ditto
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
psatish
Forum Newbie
Posts: 7
Joined: Tue Sep 27, 2005 6:34 am
Location: Hyderabad, India
Contact:

Post 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

Code: Select all

abc.php?ownerid=1
What do I do then?

Thanks and Regards
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post 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.
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

In my website, I use an Iframe 8)

I thought of changing it to querystring but CBA :P
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: index.php?somevar=somepage linking

Post 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.
psatish
Forum Newbie
Posts: 7
Joined: Tue Sep 27, 2005 6:34 am
Location: Hyderabad, India
Contact:

Post 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
Post Reply