[advanced search]
NamePros Domain Auction
Live Event This Thursday at 6PM EDT - Prebidding open now
10 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Webmaster Tutorials
User Name
Password

Old 02-11-2007, 01:27 PM   ˇ #1
LogiK
NamePros Regular
 
Name: Declan
Location: @ él Computér
Trader Rating: (10)
Join Date: Aug 2006
Posts: 389
NP$: 70.00 (Donate)
LogiK will become famous soon enoughLogiK will become famous soon enough
PHP TUTORIAL: index.php?page=yourpage

Ever wondered how websites have different url navigation?
In this tutorial i will show you how to stop using the boring:
Code:
http://mysite.com/contact.php http://mysite.com/faq.php


And teach you how to start using:
Code:
http://mysite.com/?page=contact http://mysite.com/?page=faq


Now, 1st thing you need is a basic template with your header and navigation.
Create all your other files seperately not including the template structure.

Already done that?.. Now interigate this code into the part of your template you want the page to show up in.

PHP Code:
<?
$page
= $_GET['page'];

if(
$page == "index"){
include
"index.php";
}
elseif(
$page == "contact"){
include
"contact.php";
}
elseif(
$page == "faq"){
include
"faq.php";
}
else{ include
"index.php";
}
?>


Basicly, Heres the code broken down...

PHP Code:
<?
$page
= $_GET['page'];

This starts the php code and "grabs" whatever the ?page= part of your URL is defined as, so that it can be used in the if/else statements.

PHP Code:
if($page == "index"){
include
"index.php";
}

The above sees if ?page= "index" and if it is, includes your index.php page, if it isnt it moves on to see if your page is something different.

PHP Code:
elseif($page == "contact"){
include
"contact.php";
}

After seeing if your page is set to index and finding out it isnt, this part of the code finds out if the ?page= is set to something else, in this case "contact"... and if it is set to contact, PHP includes your contact.php page.
You can add as many elseif statements as you like, depending on the number of pages you decide to use.

PHP Code:
else{ include"index.php";
}
?>

After finding out that $page is not equal to any of the pages you have set, the script then includes the default(index.php) page and ends the process.

I hope this tutorial has simplified the ?page=yourpage navigation and how it done, feel free to comment, constructive critacism is welcomed.

Thanks, Declan.


Please register or log-in into NamePros to hide ads

Last edited by LogiK : 02-11-2007 at 01:36 PM.
LogiK is offline   Reply With Quote
Old 02-11-2007, 01:31 PM   ˇ #2
USMC_1833
NamePros Member
 
Location: Iraq
Trader Rating: (4)
Join Date: Dec 2006
Posts: 191
NP$: 6.00 (Donate)
USMC_1833 is on a distinguished road
Save a Life
nice tutorial
USMC_1833 is offline   Reply With Quote
Old 02-11-2007, 03:15 PM   ˇ #3
webfreak
New Member
 
Trader Rating: (52)
Join Date: Dec 2005
Posts: 1,606
NP$: 150.00 (Donate)
webfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud ofwebfreak has much to be proud of
Diabetes Cystic Fibrosis
Excellent, simple, easy to understand tutorial. Rep added.
webfreak is offline   Reply With Quote
Old 02-14-2007, 09:40 AM   ˇ #4
Dale
NamePros Member
 
Name: Dale Hay
Trader Rating: (1)
Join Date: Nov 2005
Posts: 28
NP$: 22.00 (Donate)
Dale is an unknown quantity at this point
Nice tutorial, however you could make it shorter and simpler.

PHP Code:
<?php
if(!$_GET[page]){
include
"index.php"; // Page to goto if nothing picked
} else {
include
$_GET[page]."php"; // test.php?page=links would read links.php
}
?>


__________________
PR4 - Dale Hay . com
PR3 - Convo World (You get paid real money to post!)
NEW - Sound Upload - Upload your MP3, WMA, WAV and RA files for free!
Dale is offline   Reply With Quote
Old 02-14-2007, 10:00 AM   ˇ #5
crazyryan
NamePros Member
 
Trader Rating: (4)
Join Date: Jan 2007
Posts: 167
NP$: 0.00 (Donate)
crazyryan is on a distinguished road
Not entirely sure, but shouldn't you protect the $_GET to prevent XSS?
__________________
Proxy
crazyryan is offline   Reply With Quote
Old 02-14-2007, 10:04 AM   ˇ #6
Dale
NamePros Member
 
Name: Dale Hay
Trader Rating: (1)
Join Date: Nov 2005
Posts: 28
NP$: 22.00 (Donate)
Dale is an unknown quantity at this point
True, but using
PHP Code:
$page = $_GET[page];
would still allow a XSS attack couldn't it?
__________________
PR4 - Dale Hay . com
PR3 - Convo World (You get paid real money to post!)
NEW - Sound Upload - Upload your MP3, WMA, WAV and RA files for free!
Dale is offline   Reply With Quote
Old 02-14-2007, 10:31 AM   ˇ #7
LogiK
NamePros Regular
 
Name: Declan
Location: @ él Computér
Trader Rating: (10)
Join Date: Aug 2006
Posts: 389
NP$: 70.00 (Donate)
LogiK will become famous soon enoughLogiK will become famous soon enough
Originally Posted by Dale
Nice tutorial, however you could make it shorter and simpler.

PHP Code:
<?php
if(!$_GET[page]){
include
"index.php"; // Page to goto if nothing picked
} else {
include
$_GET[page]."php"; // test.php?page=links would read links.php
}
?>






That ^^^ would not work, because if someone put in page=catmonkeyfish PHP would try & inlcude catmonkeyfish.php, Therefore my way is a tried & tested effective way.
LogiK is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Traffic Down Under http://www.mobisitetrader.com/ Traffic Down Under
Advertise your business at NamePros
All times are GMT -7. The time now is 07:15 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0