Home arrow PHP arrow Page 2 - Developing Multipurpose Pages With PHP
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
TABLE OF CONTENTS:
  1. · Developing Multipurpose Pages With PHP
  2. · Multipurpose Web Pages
  3. · Examining The Code
  4. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Developing Multipurpose Pages With PHP - Multipurpose Web Pages
(Page 2 of 4 )

What are multipurpose pages? Put simply, they are dynamic pages that can display completely different content if a certain condition (or conditions) is met. There are both advantages and disadvantages to these types of pages:

Advantages:
  • Smaller number of pages to keep track of
  • Less space is taken up on your server
  • There are less changes to make when you redesign
Disadvantages:
  • Pages can become very long (number of lines)
  • Processing time is slowed slightly due to a large number of variable checkings
Overall, I believe that the advantages far outweigh the disadvantages. Isn't it a lot easier to keep track of one index page, instead of two? Also, doesn't one 400-line page take up less space than two 300-line pages? For me, that's usually the case, because I always limit the width of a line to the width of my screen, so I never scroll, and all lines are essentially the same length.

If you use CSS, then redesigning is even easier. You can easily setup a layout of the whole page and just jump into PHP when you want to have changing content, like a login box that is replaced by one of those "Welcome, someone, you last visited..." dialogs.

For example:

if ($something == "something") {
echo ($page1);
}
else {
echo ($page2);
}


Let me show you a tiny example of a multipurpose page in action. Let's say that Bob has a page with news, and a little log-in box on the right side. He has used the concepts I will present to you -- and explain with greater detail -- in this article to create his page.

Here's Bob's source code:

<html>
<head>
<title>Bob's Login Site</title>
<body bgcolor="#00cc00">
<?php
if ($_POST['login'] == "do") {
$name = $_POST['name'];
$pass = $_POST['password'];
$db_cnct = mysql_connect("localhost", "user", "pass") or die("Could not connect to the database!");
$db = mysql_db_select("users", $db_cnct);
$sql = "SELECT user, pass FROM users WHERE user = \"$name\" and pass = \"md5($pass)\"";
// This is for an encrypted password-protection database
$check_user = mysql_query($sql);
$users = mysql_num_rows($check_user);
if ($users < 1) {
echo ("<center>Invalid Password!</center>");
echo ('<form action="'.$PHP_SELF.'" method="post">');
echo ('<input type="text" name="name"><br />');
echo ('<input type="password" name="password"><br />');
echo ('<input type="hidden" name="login" value="do">');
echo ('<input type="submit" value="Log-in">');
echo ('</form>');
}
else {
echo ("Welcome, $name!");
}
}
else {
echo ('<form action="'.$PHP_SELF.'" method="post">');
echo ('<input type="text" name="name"><br />');
echo ('<input type="password" name="password"><br />');
echo ('<input type="hidden" name="login" value="do">');
echo ('<input type="submit" value="Log-in">');
echo ('</form>');
?>
</body>
</html>

blog comments powered by Disqus
PHP ARTICLES

- 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

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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