PHP
  Home arrow PHP arrow Page 2 - Developing Multipurpose Pages With PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Developing Multipurpose Pages With PHP
By: Unknown User
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2002-10-11

    Table of Contents:
  • Developing Multipurpose Pages With PHP
  • Multipurpose Web Pages
  • Examining The Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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>

    More PHP Articles
    More By Unknown User


     

    PHP ARTICLES

    - 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
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway