Recently I made my
website with the same approach. One php page that will display different content depending on what the viewers want. As I was on the process on developing it I found out that the php page will become cumbersome as the content it will display will increase. In your case, when the steps reaches step20 or more. So instead of using switch() statement and encode all the information needed to display in one php page with respect to each steps (steps 1 to 20 for example) in your case you could use one instruction that will do it all:
require("file");
the above function basically will insert the content of "file" as HTML. To understand how it works we will create an example. First let say that we have a file named
one which is save in the same folder with your
page.phponeCODE
<h3>This is Step 1</h3>
<?PHP
print "\nPHP things to do in step 1";
?>
above is the content of the file one. As you notice we use the <?PHP ?> php tag. Whatever text file require() will insert it consider it as an HTML texts not PHP thus it is neccessary to use the PHP tag when adding php code.
page.phpCODE
<html>
<head>
</head>
<body>
<?PHP
if(isset($_GET['step']))
require($_GET['step']);
?>
</body>
</html>
above is the page.php file. As you can see its pretty neat but it works fine and better than the swtich() statement.
Heres how it works:For example we use the page.php as
page.php?page=one. So what happened is the variable $_GET['step'] contains the string "one" which is basically the name of our file for the first step. In that case when we code
require($_GET['step'); its just the same as
require("one"); which will insert whatever content the file
one. But be sure that
one file is the same directory with the
page.php file. But if it is not or if you want to use extensions like
one.txt or
one.inc use this technique:
assuming that we have a file
one.inc which is saved in the folder
myfolder/stepspage.phpCODE
<html>
<head>
</head>
<body>
<?PHP
$location = 'myfolder/steps/';
$extension = '.inc'; //I like to use inc as extension coz it could mean include file
if(isset($_GET['step'])){
$file = $location . $_GET['step'] . $extension;
require($file);
}
?>
</body>
</html>
The final HTML code output of your page.php if we use it like this
page.php?page=one is
CODE
<html>
<head>
</head>
<body>
<h3>This is step 1</h3>
PHP things to do in step 1
</body>
</html>
Basically becuase of the
require() function whatever the content of
one.inc it is inserted in the area where we called the funtionc
require().With this technique you can have as many steps you want to take. You just have to create the files two.inc, three.inc ... twenty.inc. The best thing about this is each steps instructions and data are saved in individual file which means mentaining and debugging is easy and not cumbersome. As you can see there are few codes in the page.php as opposed to
swtich() statement in which you will crease a list of
case value:.
Reply