why use ?show=page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

why use ?show=page

Post by tarja311 »

Hi all,

I have searched but have yet to find why programmers use this method to navigate around their websites. I've found that some do not use this, instead, in the url it says something like: site.com/login.php while others say something like: site.com/?show=login

Can anyone explain why this is used and the benefits of doing this?

thanks

--tarja
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

?show=login is used if you handle many things in one PHP file.

For example:

Code: Select all

<?php
switch($_GET['show'])
{
  case "login":
    //Login stuff...
  break;
  case "register":
    //Register stuff...
  break;
  default:
    //Index (default) stuff...
}
?>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

It'san organization strategy that may make it easier to separate your presentation from application logic, like such:

Code: Select all

<?php
// index.php

include('header.php');

switch($_GET['show']) {
  case 'signup':
    include('signup.php');
  break;

  case 'login':
    include('login.php');
  break;

  case 'index':
  default:
    include('index_page.php');
  break;
}

include('footer.php');
?>
as opposed to including the header and footer files in every file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Typically the latter is used in MVC (Model View Controller) back-end designs. There is often a single actual entry point to the application where the user interacts with most things through. The former can be all sorts of things. MVC can be simpler to maintain in the end due to a single point where you need to alter many things at once.

Some swear by MVC, some don't.
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

feyd wrote:Typically the latter is used in MVC (Model View Controller) back-end designs. There is often a single actual entry point to the application where the user interacts with most things through. The former can be all sorts of things. MVC can be simpler to maintain in the end due to a single point where you need to alter many things at once
what he said.

it makes it eaiser to maintain in coding style if anything. i don't like the latter for a multitude of reasons. for one the include structure becomes convuluted i've found out. it's a pain int he ass unless you use the file as the root. secondly when you need multiple files it gets cumbersome. i still prefer pretty URL's though :)
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

what he said.

it makes it eaiser to maintain in coding style if anything. i don't like the latter for a multitude of reasons. for one the include structure becomes convuluted i've found out. it's a pain int he ass unless you use the file as the root. secondly when you need multiple files it gets cumbersome. i still prefer pretty URL's though :)[/quote]

But, if you use OOP, you will probably want to use the letter (?show=login).
tarja311
Forum Commoner
Posts: 73
Joined: Fri Oct 20, 2006 10:57 pm

Post by tarja311 »

Thanks guys. Now i understand the point of it all. :)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

ok wrote:what he said.

it makes it eaiser to maintain in coding style if anything. i don't like the latter for a multitude of reasons. for one the include structure becomes convuluted i've found out. it's a pain int he ass unless you use the file as the root. secondly when you need multiple files it gets cumbersome. i still prefer pretty URL's though :)
But, if you use OOP, you will probably want to use the letter (?show=login).[/quote]
did i not just say that? lol, i was agreeing with feyd. also, you don't need to use OOP in order to use the query string. you don't need to use OOP to use the onsingle entry point pattern either
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

The [ q u o t e ] tag disappeared from my post... weird. [/quote]
Post Reply