PDA

View Full Version : Quick question regarding "case" in PHP.



cr3ative
05-20-2005, 11:34 AM
Hello all,

I've built a small PHP script for my website which consolidates about 10 different pages into one. Let me explain.

The code structure is a little like this:

HTML Code for page up until content is required
PHP inserts content here depending on which page was requested
Footer HTML

I've done this using the CASE function in PHP, and at present it looks like this:


<?php
// Start PHP script.
switch($_SERVER['QUERY_STRING']) {

case 'pageone':
echo "content for page one";
break;

case 'pagetwo':
echo "content for page two";
break;

default:
echo "normal index";
}
So a request for the page looks like:
index.php?pageone
And if there's any sort of typing error, such as
index.php?page one
It will serve up the "default" page.


However, this isn't exactly what I want to happen.
I'd prefer that when a typo is hit, that some content is served stating that there was an error in the request, rather than just serving the default page.

Is this possible? I'm rather new to PHP.

(My current PHP is www.gerryhyh.f2s.com/paul/content/index.php, and the code can be found at http://www.gerryhyh.f2s.com/paul/content/php.txt (which I know is completely uncompliant. I'm working on that :))

Regards,
cr3ative

cr3ative
05-20-2005, 02:33 PM
I've made a semi-bodged workaround for now:

I've set case '': to be my index page, and default: to be an error page.

cr3ative

mwinter
05-20-2005, 04:24 PM
I've made a semi-bodged workaround for now:

I've set case '': to be my index page, and default: to be an error page.That's all I was going to suggest. You've defined clauses for all expected cases, and treat other cases as errors. Seems reasonable to me.

Mike