MetalHawk Posted May 29, 2006 Share Posted May 29, 2006 Hello!I have a question related to switch case/include function in php. <?phpswitch($_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.<?phpswitch($_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 https://forums.phpfreaks.com/topic/10689-switch-case-problem/ Share on other sites More sharing options...
trq Posted May 29, 2006 Share Posted May 29, 2006 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]<?phpif (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 https://forums.phpfreaks.com/topic/10689-switch-case-problem/#findComment-39887 Share on other sites More sharing options...
MetalHawk Posted May 29, 2006 Author Share Posted May 29, 2006 I used a slight variation of your code above, which works as I wanted it to.[code]<?phpswitch($_GET['p']){case "1": header("location:http://www.domain.com/?cat=123"); exit; break;default: break;}; ?>[/code]thanks for help! Link to comment https://forums.phpfreaks.com/topic/10689-switch-case-problem/#findComment-39908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.