CODE
<?php
$page = $_GET['id'];
switch($page){
case '': //sets the default page this is two single quotes not one double quote
include("index.php"); //defines the default page that will be shown
break; //break in the script so you can start a new one
case 'staff': //sets the name that will be shown in the address bar when you click the "Staff" link.
include("about.php"); //sets the staff page notice it is different than the case so people don't know your page
break; //breaks the script so you can start a new case
} // closes the switch
?> // closes the script
$page = $_GET['id'];
switch($page){
case '': //sets the default page this is two single quotes not one double quote
include("index.php"); //defines the default page that will be shown
break; //break in the script so you can start a new one
case 'staff': //sets the name that will be shown in the address bar when you click the "Staff" link.
include("about.php"); //sets the staff page notice it is different than the case so people don't know your page
break; //breaks the script so you can start a new case
} // closes the switch
?> // closes the script
Lets break it down:
CODE
<?php
Opens the php code block
CODE
$page = $_GET['id'];
defines the $page variable and tells the script to get the page name after the = sign in index.php?id=whatever
CODE
switch($page){
tells the script to switch the name of the file such as about.php with the case set in "case"
CODE
case '':
defines the name of the page put two single quotes (not one double quote) and leave it blank in between to set the default page or put something in such as "staff" to make your link to the about.php page index.php?id=staff
CODE
include("index.php");
includes the page that the name will be switched with the "case" in this case it won't be switched because the case'': was left blank so this would be your default page
CODE
break;
puts a break in the script so you can define new "case"s and "include"s.
CODE
}
this closes the "switch" function
CODE
?>
this closes the php code block
This concludes my tutorial on quick/easy/secure php dynamic navigation. Hope this helps you in your future php coding!!!