[PHP] Navigation

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
Have you seen the URL where they say index.php?content=home and where the index page stays and the content change, here is a small tutorial where I will explain this.

In the index.php file, you shall add this code before the <html> tags:

Code:
<?php
$content = $_GET['content'];
if($content == "") {
$content = "home";
}
?>

In the first 2 lines is will make a variable where it will set the $content variable to what the content is in the URL. If you have an URL like this "index.php?content=aboutus" it will set the content variable to aboutus.

In the line 3 to 6, it sets the variable to home if the content variable is not set. Those lines are very important because if you come into the site for you first visit the content variable is not set, so if you do not have these lines you will get an error message.

Where you what the content to be include you insert this code.

Code:
<? php
include("$content.php");
?>

When you now link to your page you shall use this link:

Code:
index.php?content=aboutus

The link above will link to a page called aboutus.php.
 

CheetahShrk

New Member
Messages
204
Reaction score
0
Points
0
Re: PHP Navigation

That is one of the most posted tutorial on the internet on php navigation. It's unsecure though, best way is to add switch cases to make sure what a person is requesting is what you allow.
 

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
Re: PHP Navigation

Oh well, just a tutorial..Besides I have a massive project with a friend and PHP including HTML, mySQL, CSS and Jaca... =D
 

BrettFreeman

New Member
Messages
106
Reaction score
0
Points
0
Re: PHP Navigation

PHP:
   $page = $_GET["i"];
switch($page){
   case "news":
      include("./inews/show_news.php");
      break;
   default:
      include("./inews/show_news.php");
      break;
}

Thats a bit of a more secure way to do it.
 
Top