USA United States UK United Kingdom

1 File, Multi Page website!

In some situations, you can upload 1 PHP file, that will quite litterly run as your website.

This can be done in 3 ways, it can be done statically (Hard Coded), Dynamically (With MySQL) or Dynamically (With Flat File System)

I will show you a way of doing just this, statically (For now, I swear I will post 2 dynamic versions!)

Firstly, we need to start the file,

To start a PHP file, we must do this;

(To tell the server to stop executing)

I will now show you a nifty function called, SWITCH. This function allows us to easily structure a large IF array based on comparing information within the variable, and the static content within the structure.

Before we go out and structure a massive static database, we must get the variable that we want to use to tell which page to load.

Lets call this variable, $page. To give a value to this variable, we must add this just below

$page = $_GET['p'];

This will now set $page’s value to what ever the value is behind filename.php?p, for instance, filename.php?p=home, will set $page to the string “home”.

Now we have our source, the time to make our comparison database is at hand;

Using the switch function we enter the following;

switch($page){

}

Within the Switch function, we need to enter;

case “home”:

break;

For each page we want, but replace the “home” with “whatevernameyouwant” for each page.

Now lets set a default page, this can be done by entering;

default:

break;

There are a few ways to display some output in PHP, one of the ways we are going to do it, is the most simple and cut `n paste method. Which can be done, by closing the PHP identifiers just after our CASE. For example;

case “home”:

?>

We can then proceed to enter HTML just after the ?>. Remember that once you have finished your HTML, you need to put in another

Out file so far;

<h1>This is a test page!</h1>

To add more options, simply add more Cases and breaks. E.G.

<h1>Home Page!</h1>
<h1>About Us Page!</h1>

This is the most simple form of 1 file website.

Hope you enjoyed it, and I will be posting a MySQL and Flat File System version soon. Stay Tuned!

Tags: , , , , , , , , , , ,

Sunday, September 21st, 2008 Uncategorized

No comments yet.

Leave a comment