Subscribe to get design
tips, latest trends, free
stuff and more.
It doesn't look like an e-mail address


  Web Programming PHP Navigation Using Switch

Navigation Using Switch

Will PHP Mar 30, 2007

Navigation Using SwitchSo these days there are ways to exploit your PHP automated navigation with selecting files from modules and including them autimatically according to the URL variables. Not good.

Today I'm going to explain to you a simple method, which is safe and easily customizeable.

$x = $_GET[x];
switch($x) {

This is just the beginning of our navigation script. I'll explain this for you...

The first line gets $x from the URL. We don't have to worry about htmlspecialchars or stripslashes, because there are a finite amount of options to choose from later on.

switch($x) starts an "array" of options that $x must comply with.

The 3rd and 4th lines are what the script will do if $x is not set, or does not comply with the rules set.

Moving onto the next chunk...

break; case "tutorials":

This code basically translates to:

if($x=="tutorials") {

Which translates to English as: "If $x's value is tutorials, include tutorials.php"

To access tutorials.php, you'd go to

So we'd go on and on for a while, eventually ending up with something like this:

switch($x) {

break; case "tutorials":

break; case "snippets":

break; case "script_downloads":

break; case "banners":

break; case "code_lessons":

What you do now is quite similar to what you do with any other navigation. Put this script in whichever page you want, where you want the content to be, and then upload it. You're sorted.

Just to recap, say you put this script on, you'd go to to include the banners page.

subscribe to newsletter