Jump to content
xisto Community
mahirharoon

Php Page Switcher

Recommended Posts

this is my first topic(not post)

i had posted it in another place

<?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;}?>
instructions:

case "guestbook": include([u]'guestbook.php'[/u]); break;
= change - guestbook.php to the page url

 

forum - change to your id (underlined) which will come in

index.php?id=[u]forum[/u]

$variable = $_GET['id'];
-change id to what you want here (underlined) index.php?id=123

Share this post


Link to post
Share on other sites

I am thinking that the Code should read as follows so that the default case gets handled after the check for "id".

<?php$variable = $_GET['id'];switch($variable) {case "guestbook": include('guestbook.php'); break;default: include('home.php'); break;}?>
The Default case is a 'fall through' value. If there is not a 'break' for any other, correct, value, then the Default is applied.
Correct me if I am wrong.

Thanks.

Share this post


Link to post
Share on other sites

I'm pretty sure 'default' is alway supposed to come last, because it has to check all the other values to know if it has the default. If you put the default first, it's not even going to check any of the cases.And it might be better to use the $_POST variable, instead of $_GET, because get shows in the URL. You can look it up, if you want. If you use get, you could do the same kind of thing with javascript, because I think you can get the variables from a method='get' with javascript, too. That way, it doesn't matter if you have PHP installed on the server, but it might matter what browser you're using.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.