Jump to content

Switch case problem


MetalHawk

Recommended Posts

Hello!

I have a question related to switch case/include function in php.
<?php
switch($_GET['p'])
{
case "1": default: break;
case "2": die(include "concerts.php"); break;
case "3": die(include "reviews.php"); break;
default:
break;
}
; ?>
I have no trouble if I form a switch case & include with files that have extensions at the end, but I have a problem (include not working) if I try to include a page which doesn't have an extension (cms generated page).
I want to know is it possible, & if it, what should I change i next code, to include files like these?

Here is the example of the non-working code. I tried with / & without on the begining, same result.

<?php
switch($_GET['p'])
{
case "1": default: break;
case "2": die(include "/?cat=123"); break;
case "3": die(include "/?cat=124"); break;
default:
break;
}
; ?>


Thanks for help.
Link to comment
Share on other sites

For starters. Dont put your default action as the first case in a switch, the others will never work.

2nd. You cannot call an include as an argument to die().

3rd. You cannot include() using variables passed through the url.

You might try...
[code]
<?php

if (isset($_GET['p'])) {
  switch($_GET['p']) {
    case 3: header("Location : {$_SERVER['PHP_SELF']}?cat=124"); break;
    case 2: header("Location : {$_SERVER['PHP_SELF']}?cat=123"); break;
    default: break;
  }
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.