Hi, Guest ~ Login or Register

Navigation using switch

Navigation using switch

Listed In PHP and MySQL » Systems and Features — Viewing Full Tutorial
So 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.

Working Beta

  1. The Forums
    These are mostly functional. If you see any weird bugs, post a thread about it and an administrator will do something.
  2. Tutorial Writing
    You can now submit tutorials to the brand new management system.
  3. Tutorials Home
    View tutorials by categories and search for them here.
  4. Shoutbox
    See below. Registered users only!

Register

Newest User

Say hi to Lirette25! Lirette25 joined on Monday, 14th July.

Sponsor

Check out Next day fake id

Shoutbox