Load pages using URL variables and PHP include() function

we have seen the conceptual design for index.php page. This page can be defined the "container" of our site. Inside the #main section we will load all the other pages, arranging the use of URL variables and PHP include() function. In this way, we will have a single page that define the global layout for our site (index.php: topbar, navigation bar, footer).
An URL variable is a variable visible from the user into the browser

navigation bar identify from the char "?" + "varname". This is the typical approach using URL variable:

A PHP URL variable is identified from the following code:


Imagine our site have only tree pages: Home, About me, Interests; we want to use URL variables to load the relative pages saved into include folder of our site root (take a look to the complete site structure post).

Copy and paste this code inside the #main section:


//If is defined URL variable 'aboutme'
// include page about me
//else if is defined URL variable 'interests'
}else if(isset($_GET['interests'])){
// include page interests
// in all other cases include the home page
} else {

In this way, when is defined an URL variable that satisfies some criteria (in this case the name), the PHP code load the relative page. In all other cases, or if is not defined a URL variable, load the default page in-home.php (our home page).

In the next lesson I will explain an example of a typical navigation bar that use link with URL variable to navigate on your site.


  1. original content from "http://woork.blogspot.com/2007/10/load-page-using-url-variables-and-php.html"............


Total Pageviews