Navigation Using Switch

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.

<?php
$x = $_GET[x];
switch($x) {
default:
include('../home.php');

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":
include('../tutorials.php');

This code basically translates to:

if($x=="tutorials") {
include('../tutorials.php');
}

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

To access tutorials.php, you'd go to www.site.com/switchfile.php?x=tutorials

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

<?php
switch($x) {
default:
include('../home.php');

break; case "tutorials":
include('../tutorials.php');

break; case "snippets":
include('../snippets.php');

break; case "script_downloads":
include('../script_downloads.php');

break; case "banners":
include('../banners.php');

break; case "code_lessons":
include('../code.php');
}
?>

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 www.site.com/nav.php, you'd go to www.site.com/nav.php?x=banners to include the banners page.


Related Articles

  • PHP Navigation and Connecting to a MySQL Database
    PHP Navigation and Connecting to a MySQL Database
  • PHP Navigation
    Using PHP, you can have your entire site layout in only one file. If you dont know what this tutorial is, read it anyway. I wanted to learn how to do something like this for about 2 years. Nothing worked better than PHP Navigation. Not frames, not anything.
  • Sometimes It's The Little Things That Count!
    Recently, I decided to switch my web hosting company. I had been with my last hosting company for almost two years but I was having continuing problems with their system. So I switched and I am up and running wi...
  • Navigation Tricks
    This is the a method that we prefer to use, typically we will use this on all of our pages in one form or another. I feel that it is superior to image maps and JAVA for a few reasons: Low maintainence. Everybody pretty much can figure out what they mean. By using the ALT description- it works ...
  • Stylesheet Switcher
    This tutorial is an easy approach to switching your stylesheets faster. The scripts are provided in easy to read graphics.
  • The Cheapest Domain Names - What do you get for $1.99?
    There are several sites on the internet claiming to offer the cheapest domain names. If you look hard enough, you can find domain names for as low as $1.99 or $2.99 per year. So, whats the catch?
  • Introduction to Procedural Programming
    Well start of with if
    Here is the basic usage of it
    variable would be something like $variable
  • Server Side Includes
    This very helpful tutorial makes it much easier to make changes throughout your entire website. It is easy to follow and has plenty of code.
  • Are You Being Scammed By Your Web Design Company?
    This is a growing concern among many business owners. Does your web design company own you? This may be possible if youve allowed them to host your web site for you and also register your domain name for your company...
  • Rate it! Poll
    This is an awesome tutorial that will show you step by step how to create a way to take a poll on your site. People for the most part enjoy participating in polls so this could also help you bring extra traffic to your site.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.