Home arrow PHP arrow Page 3 - Developing Multipurpose Pages With PHP

Developing Multipurpose Pages With PHP

Sick of having a site that's composed of 50 PHP scripts? In this article we will learn the concepts of multipurpose pages with PHP -- a simple yet powerful idea.

Author Info:
By: Unknown User
Rating: 3 stars3 stars3 stars3 stars3 stars / 3
October 11, 2002
  1. · Developing Multipurpose Pages With PHP
  2. · Multipurpose Web Pages
  3. · Examining The Code
  4. · Conclusion

print this article

Developing Multipurpose Pages With PHP - Examining The Code
(Page 3 of 4 )

First, the script checks if there is a username and password being passed through a form via the HTTP POST method. If there is none, the script will display the code that will prompt for a username and password.

If they are present then the script will run queries on the database to check if a valid username and password combo was used. If it is, then the script will display the message "Welcome, $name!", otherwise it'll display an error and prompt the user again.

As I said earlier, multipurpose pages use control structures to choose one of many possible 'templates' to generate a specific, and yet dynamic, page. When using forms, which I have seen to be the most common element used with multipurpose, you can easily implement if/else to display either the form, or the result text.

Multipurpose can also be used to create forums with GET values instead of POST values. This enables you to create links instead of forms that will get you to a certain version of one page. Although not evident until forums are made, a multipurpose page can be in any number of parts, not just two.

Multiple (3+) parts allows for multiple forms, or in the case of forums, a forum ID, a thread ID, and a message ID. Other values can also be tagged on. This increases information-gathering capabilities, and continues to cut down on number of pages and overall space taken up on servers.

A Practical Example
Here's an example of a multipurpose web page. See if you can figure out what it does:

$forum = $_GET['forum'];
if (!isset ($forum) ) {
$sql = "SELECT forums, ID FROM master_list";
$get_forums = mysql_query($sql);
while ($forums = mysql_fetch_array($get_forums) ) {
echo ('<a href="forums.php?forum'.$forums["ID"].'">'.$forums["forums"].'</a><br />');

else {
$thread = $_GET['thread'];
if (!isset ($thread) ) {
$sql = "SELECT thread, ID FROM forum".$forum;
$get_threads = mysql_query($sql);
while ($threads = mysql_fetch_array($get_forums) ) {
echo ('<a href="forums.php?forum='.$forum.'&thread='.$threads["ID"].'">');
echo ($threads["thread"].'</a><br />');
else {
$sql = "SELECT messages FROM thread".$thread;
$get_messages = mysql_query($sql);
while ($messages = mysql_fetch_array($get_messages) ) {
echo ('<table><tr><td>'.$messages["message"].'</td></tr></table>');

This example uses the same principals and the same overall concept as the first example, including the use of Superglobal arrays and control structures.

This example is easy to expand, because the main difference between one page and the next is the name of variables, the number of if/else statements, and the number of parts.

If/else control structures can be substituted with a select case structure if you'd prefer

Quick Tips
  • When designing a site, always do HTML first, then incorporate PHP
  • Start with multipurpose pages -- don't code and then convert
  • Think of the future and never use commands that have new alternates unless they produce different effects.
  • GET data doesn't have to come from a form, it can be 'placed in' by links instead

blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials