Go Back   Themers Club : Computers , Mobiles and Web Development Themes > Webmaster forum > Website Design and Content

Website Design and Content Discussion pertaining to website design : Everything related to Databases , Graphics & Multimedia , Programming , HTML ,..

Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2009, 10:00 AM
Spiral's Avatar
Spiral Spiral is offline
Super Moderator
 
Join Date: Apr 2008
Posts: 1,451
Rep Power: 18
Spiral is on a distinguished road
Default PHP tutorial, for PHP navigation.

Allot of people ask me how to do those "cool" page nav URL's in PHP

Code:
i.e. http://www.yourwebsite.com/index.php?page=downloads
Thos things...

So in this tutorial i am going to explain how to do it!

This is pretty baisic code so it shouldn't get too confusing.

PHP Code:
<?php 
switch ($HTTP_GET_VARS[page])  




// Default page 
default: 

include 
"site/index.php"

break; 

// Downloads page 
case 'resources=downloads'

include 
'site/downloads.php'

break; 

//Scripts - case 
case 'resources=scripts'

include 
'site/scripts.php'

break; 



?>
the first thing you need to notice is this bit

"$HTTP_GET_VARS[page]" now this bit is the main part, the bit where is says [page] thats what the file is going to be, so for this example to get to the downloads page we go to

index.php?page=downloads

But if you changed that [page] to say [nav] then it would be

index.php?nav=downloads

"default:" this is the next bit you need to think about, this is your default page, so say if someone just went to index.php then this is the bit that would be told to display.

include "site/index.php"; This is most likely the phrase you will use the most at a baisic level of PHP, this is the include page tag, so in this case we are saying

If someone points there browser to [Only Registered users can see links . Click Here To Register...] then its going to include the file site/index.php

"break;" This bit is just telling the server that thats the end of the code for that case.

case 'resources=downloads': This is for the downloads page, so when someone visits [Only Registered users can see links . Click Here To Register...] then its going to include site/downloads.php

"}" This is telling the server, that your now not defining the contents of [page]

Right then!

Summing up:


switch ($HTTP_GET_VARS[page]) - You change the "page" thing to what you want it to be..

i.e. if you want it to be index.php?number=somthing

then you change it from switch ($HTTP_GET_VARS[page])

to

switch ($HTTP_GET_VARS[number])


case 'resources=downloads': - for this you must remmeber not to remove the "resources=" bit if you do, it won't work!

but the bit after the = sign, change that to what you want to be.

So final example.



PHP Code:
<?php 
switch ($HTTP_GET_VARS[nav])  




// Default page 
default: 

include 
"news.php"

break; 

// Forums 
case 'resources=forums'

include 
'forums/index.php'

break; 

// Downloads page 
case 'resources=downloads'

include 
'downloads.php'

break; 



?>
*** THINGS TO REMEMBER ***


The fact that i have used index.php?somthing=somthing in this example means nothing..

you can put this on any page that you want so it could be

[Only Registered users can see links . Click Here To Register...] if you so desired :P

Hope you all got it, and enjoyed it and have learned somthing!

Cheers
Reply With Quote
  #2  
Old 07-13-2009, 07:08 AM
laxman2021 laxman2021 is offline
Junior Member
 
Join Date: Jul 2009
Posts: 5
Rep Power: 0
laxman2021 is on a distinguished road
Default

Not Found
The requested document was not found on this server.

Web Server at yourwebsite.com
Reply With Quote
  #3  
Old 07-18-2012, 11:08 PM
chrishbonang chrishbonang is offline
Junior Member
 
Join Date: Jul 2012
Posts: 4
Rep Power: 0
chrishbonang is on a distinguished road
Default

PHP one type of programming language. It is very useful for create website. It is easily understand language. If you want to learn then you can get many information in internet. It is very useful for web developer.
Reply With Quote
  #4  
Old 09-19-2012, 01:49 PM
rasynomarlo rasynomarlo is offline
Junior Member
 
Join Date: Aug 2012
Posts: 21
Rep Power: 0
rasynomarlo is on a distinguished road
Default

Well, this is very useful and informative post. But for a person who is a beginner it would be somewhat typical to understand some of the parts of the coding. I would also like to say that for the beginners w3schools is one of the best websites through which they can gain a strong knowledge upon PHP.
Reply With Quote
Reply

Bookmarks

Tags
php navigation, php tutorial


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

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


All times are GMT. The time now is 12:40 PM.


Powered by vBulletin® Version 3.7.6
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.