Simple Navigation Switch
Views:
Author: Chris
Alright, say you have a template and you want to include pages just in the middle of your site without having to copy and past the template on every page, well switch can help you!


<?php

switch($_GET[page]) { //$_GET[page] is the url, eg site.com/?page=xxx you can change [page] to anything and it will change the URL's



default: //default page to include

include('main.php');

//other files - remember to link your files to site.com?page=whatever (or use modrewrite to make them site.com/page)

break; 



case 
"tutorials":

include(
'tutorials.php');

break; 



case 
"contact":

include(
'contact.php');

//add more of these as needed, it is usually safer to add something to the name of the file to include so people don't guess the url and try to hack it, such as contact.php could be contact.inc.php, then again I just told you inc so don't try that now, do something different

break; 



case 
"VAR"//VAR is at the end of the url, so if somebody types in ...?=VAR it will include the file mentioned below

include('whatyouwant.php'); //sometimes you might need a slash at the start or a $_SERVER[DOCUMENT_ROOT]."whatyouwant.php"

break;



//End switch

?> 





Hope that helps!



1



Comments
You must be logged in or register an account with us before posting a comment.
Statistics
Member Stats Online Members, read legend below: .
Registered Users: 5 registered AND activated.
Member Level Legend NOTE: If the username is underlined it means they may just have the page open and not actually be surfing the site. Administrator
Home

Membership Login

Shout Box

» GO FULL!
Please login to post a shout. » Turn OFF chat!

Point Leader board

© Copyright 2006 - 2008 Tutnation.com and ChrisTheFeral.com