PHP                   

   Contact
   Search
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Messages
   Chat
   MCSE
   Linux
   Cabling   
   ActionScript
   Downloads
   E-Cards   
 
    
    

Under Development...

PHP is a platform independent, server-side scripting language.  You will need it installed on you web server to make full use of these scripts.

PHP KEYWORDS:

and do foreach new switch while
break else function not this
case elseif global or true
class extends if require var
continue false include return virtual
default for list static xor


Variable Declarations
Variable declarations are prefixed  with a $.

<?php
   $name = "Rufus";   // declaration
?>

<html>
   <head>
      <title>A simple PHP document</title>
   </head>
   <body style = "font-size: 2em">
      <p>
         <strong>
            <!-- print variable name’s value -->
            Welcome to PHP, <?php print( "$name" ); ?>!
         </strong>
      </p>
   </body>
</html>

-----------------------------------------------------------------------------------------------------------
Data Types

<html>
   <head>
      <title>PHP data types</title>
   </head>
   <body>
      <?php
         // declare a string, double and integer
         $testString = "3.5 seconds";
         $testDouble = 79.2;
         $testInteger = 12;
      ?>
      <!-- print each variable’s value -->
      <?php print( $testString ) ?> is a string.<br />
      <?php print( $testDouble ) ?> is a double.<br />
      <?php print( $testInteger ) ?> is an integer.<br />
      <br />
      Now, converting to other types:<br />
      <?php 
         // call function settype to convert variable
         // testString to different data types
         print( "$testString" );
         settype( $testString, "double" );
         print( " as a double is $testString <br />" );
         print( "$testString" );
         settype( $testString, "integer" );
         print( " as an integer is $testString <br />" );
         settype( $testString, "string" );
         print( "Converting back to a string results in 
            $testString <br /><br />" );
                    
         $data = "98.6 degrees";
         // use type casting to cast variables to a
         // different type                         
         print( "Now using type casting instead: <br />
            As a string - " . (string) $value .
            "<br />As a double - " . (double) $value .
            "<br />As an integer - " . (integer) $value );
      ?>
   </body>
</html>
------------------------------------------------------------------------------------------------------------
Operators - Mathematical and Comparative
<html>
   <head>
      <title>Using arithmetic operators</title>
   </head>
   <body>
      <?php
         $a = 5;
         print( "The value of variable a is $a <br />" );
         
         // define constant VALUE
         define( "VALUE", 5 );
         // add constant VALUE to variable $a
         $a = $a + VALUE;
         print( "Variable a after adding constant VALUE 
            is $a <br />" );
      
         // multiply variable $a by 2
         $a *= 2;
         print( "Multiplying variable a by 2 yields $a <br />" );
      
         // test if variable $a is less than 50
         if ( $a < 50 )
            print( "Variable a is less than 50 <br />" );
         // add 40 to variable #a
         $a += 40;
         print( "Variable a after adding 40 is $a <br />" );
         // test if variable $a is 50 or less
         if ( $a < 51 )
            print( "Variable a is still 50 or less<br />" );
         // test if variable $a is between 50 and 100, inclusive
         elseif ( $a < 101 ) 
            print( "Variable a is now between 50 and 100, 
               inclusive<br />" ); 
         else 
            print( "Variable a is now greater than 100
               <br />" ); 
           
         // print an uninitialized variable
         print( "Using a variable before initializing: 
            $nothing <br />" );
         // add constant VALUE to an uninitialized variable
         $test = $num + VALUE;
         print( "An uninitialized variable plus constant 
            VALUE yields $test <br />" );
         // add a string to an integer
         $str = "3 dollars";
         $a += $str;
         print( "Adding a string to an integer yields $a
            <br />" );
      ?>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
Expressions

<html>
   <head>
      <title>Regular expressions</title>
   </head>
   <body>
      <?php
         $search = "Now is the time";
         print( "Test string is: '$search'<br /><br />" );
         // call function ereg to search for pattern ’Now’
         // in variable search
         if ( ereg( "Now", $search ) )
            print( "String 'Now' was found.<br />" );
         // search for pattern ’Now’ in the beginning of 
         // the string
         if ( ereg( "^Now", $search ) ) 
            print( "String 'Now' found at beginning 
               of the line.<br />" );
            
         // search for pattern ’Now’ at the end of the string
         if ( ereg( "Now$", $search ) ) 
            print( "String 'Now' was found at the end 
               of the line.<br />" ); 
            
         // search for any word ending in ’ow’
         if ( ereg( "[[:<:]]([a-zA-Z]*ow)[[:>:]]", $search,
            $match ) ) 
            print( "Word found ending in 'ow': " .
               $match[ 1 ] . "<br />" );
            
         // search for any words beginning with ’t’
         print( "Words beginning with 't' found: ");
         while ( eregi( "[[:<:]](t[[:alpha:]]+)[[:>:]]",
            $search, $match ) ) {
            print( $match[ 1 ] . " " );
           // remove the first occurrence of a word beginning 
           // with ’t’ to find other instances in the string
           $search = ereg_replace( $match[ 1 ], "", $search );
         }   
         print( "<br />" );
      ?>
   </body>
</html>
-------------------------------------------------------------------------------------------
Displaying User/Client System and Environment Information

PHP offers many built-in variables for information gathering about the scripts environment.  

Client
$REMOTE_ADDR = IP address of client.
$HTTP_USER_AGENT = Browser Version of client.
$HTTP_COOKIE_VARS = data contained in cookies on client's pc.

Server
$SERVER_NAME = server name where script is running.
$SERVER_ADDR = IP address of server where script is running.
$HTTP_GET_VARS = data posted to server using "get".
$HTTP_POST_VARS = data posted to server using "post".

$GLOBALS = array of all global variables

Example Using $GLOBALS:

<html>
   <head>
      <title>Environment Variables</title>
   </head>
   <body>
      <table border = "0" cellpadding = "2" cellspacing = "0"
         width = "100%">
      <?php
         // print the key and value for each element in the 
         // in the $GLOBALS array
         foreach ( $GLOBALS as $key => $value ) 
            print( "<tr><td bgcolor = \"#11bbff\">
               <strong>$key</strong></td>
               <td>$value</td></tr>" );
      ?>
      </table>
   </body>
</html>

        

Writing and Reading a Cookie

HTML Document:

<html>
   <head>
      <title>Writing a cookie to the client computer</title>
   </head>
  

   <body style = "font-family: arial, sans-serif; 
      background-color: #99CCFF">
      
      <h2>Click Write Cookie to save your cookie data.</h2>
   
      <form method = "post" action = "cookies.php"
            style = "font-size: 10pt">
         <strong>Name:</strong><br />
         <input type = "text" name = "NAME" /><br />
         <strong>Height:</strong><br />
         <input type = "text" name = "HEIGHT" /><br />
         <strong>Favorite Color:</strong><br />
         <input type = "text" name = "COLOR" /><br />
         <input type = "submit" value = "Write Cookie" 
            style = "background-color: #F0E86C; color: navy;
            font-weight: bold" /></p>
      </form>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
PHP Document:

<?php 
   // Fig. 29.21: cookies.php
   // Program to write a cookie to a client's machine
   
   // write each form field’s value to a cookie and set the 
   // cookie’s expiration date
   setcookie( "Name", $NAME, time() + 60 * 60 * 24 * 5 );
   setcookie( "Height", $HEIGHT, time() + 60 * 60 * 24 * 5 );
   setcookie( "Color", $COLOR, time() + 60 * 60 * 24 * 5 );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
   <head>
      <title>Cookie Saved</title>
   </head>
   <body style = "font-family: arial, sans-serif">
      <p>The cookie has been set with the following data:</p>
      
      <!-- print each form field’s value -->
      <br /><span style = "color: blue">Name:</span> 
         <?php print( $NAME ) ?><br />
      
      <span style = "color: blue">Height:</span> 
         <?php print( $HEIGHT ) ?><br />
      
      <span style = "color: blue">Favorite Color:</span>
      
      <span style = "color: <?php print( "$COLOR\">$COLOR" ) ?>
      </span><br />
      <p>Click <a href = "readCookies.php">here</a>
         to read the saved cookie.</p>
   </body>
</html>
--------------------------------------------------------------------------------------------------------------
Reading the Cookie - PHP Document

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Fig. 29.24: readCookies.php                        -->
<!-- Program to read cookies from the client's computer -->
<html xmlns = "http://www.w3.org/1999/xhtml">
   <head><title>Read Cookies</title></head>
   <body style = "font-family: arial, sans-serif">
      <p>
         <strong> 
            The following data is saved in a cookie on your
            computer.
         </strong>
      </p>
      <table border = "5" cellspacing = "0" cellpadding = "10">
         <?php
            // iterate through array $HTTP_COOKIE_VARS and print
            // name and value of each cookie
            foreach ( $HTTP_COOKIE_VARS as $key => $value )
               print( "<tr>
                  <td bgcolor=\"#F0E68C\">$key</td>
                  <td bgcolor=\"#FFA500\">$value</td>
                  </tr>" );
         ?>
      </table>
   </body>
</html>
-----------------------------------------------------------------------------------------------------------------
Form Processing

Form Processing - HTML Document

<html>
   <head>
      <title>Sample form to take user input in XHTML</title>
   </head>
   <body>
   
      <h1>This is a sample registration form.</h1>
      Please fill in all fields and click Register.
   
      <!-- post form data to form.php -->
      <form method = "post" action = "form.php">
         <img src = "images/user.gif" alt = "User" /><br />
         <span style = "color: blue">
            Please fill out the fields below.<br />
         </span>
         <!-- create four text boxes for user input -->
         <img src = "images/fname.gif" alt = "First Name" /> 
         <input type = "text" name = "fname" /><br />
      
         <img src = "images/lname.gif" alt = "Last Name" />
         <input type = "text" name = "lname" /><br />
      
         <img src = "images/email.gif" alt = "Email" /> 
         <input type = "text" name = "email" /><br />
      
         <img src = "images/phone.gif" alt = "Phone" /> 
         <input type = "text" name = "phone" /><br />
      
         <span style = "font-size: 10pt">
            Must be in the form (555)555-5555</span>
         <br /><br />
      
         <img src = "images/downloads.gif" 
            alt = "Publications" /><br />
         <span style = "color: blue">
            Which book would you like information about?
         </span><br />
         <!-- create drop-down list containing book names -->
         <select name = "book">
            <option>Internet and WWW How to Program 2e</option>
            <option>C++ How to Program 3e</option>
            <option>Java How to Program 4e</option>
            <option>XML How to Program 1e</option>
         </select>
         <br /><br />
         <img src = "images/os.gif" alt = "Operating System" />
         <br /><span style = "color: blue">
            Which operating system are you currently using?
         <br /></span>
         <!-- create five radio buttons -->
         <input type = "radio" name = "os" value = "Windows NT"
            checked = "checked" /> 
            Windows NT
      
         <input type = "radio" name = "os" value =  
            "Windows 2000" />
            Windows 2000
      
         <input type = "radio" name = "os" value =  
            "Windows 98" />
            Windows 98<br />
      
         <input type = "radio" name = "os" value = "Linux" /> 
            Linux
      
         <input type = "radio" name = "os" value = "Other" /> 
            Other<br />
          <!-- create a submit button -->
         <input type = "submit" value = "Register" />
      </form>
   </body>
</html>
-------------------------------------------------------------------------------------------------------
Form Processing - PHP Document

<html>
   <head>
      <title>Form Validation</title>
   </head>
   <body style = "font-family: arial,sans-serif">
      <?php
         // determine if phone number is valid and print
         // an error message if not
         if ( !ereg( "^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$",
            $phone ) ){
            print( "<p><span style = \"color: red; 
               font-size: 2em\">
               INVALID PHONE NUMBER</span><br />
               A valid phone number must be in the form
               <strong>(555)555-5555</strong><br />
               <span style = \"color: blue\">  
               Click the Back button, enter a valid phone
               number and resubmit.<br /><br />
               Thank You.</span></p></body></html>" );
            die(); // terminate script execution
         }
      ?>
      <p>Hi 
         <span style = "color: blue">
            <strong>
               <?php print( "$fname" ); ?>
            </strong>
         </span>.
         Thank you for completing the survey.<br />
   
         You have been added to the 
         <span style = "color: blue">
            <strong>
               <?php print( "$book " ); ?>
            </strong>
         </span>
         mailing list.
      </p>
      <strong>The following information has been saved 
          in our database:</strong><br />
   
      <table border = "0" cellpadding = "0" cellspacing = "10">
         <tr>
            <td bgcolor = "#ffffaa">Name </td>
            <td bgcolor = "#ffffbb">Email</td>
            <td bgcolor = "#ffffcc">Phone</td>
            <td bgcolor = "#ffffdd">OS</td>
         </tr>
         <tr>
            <?php
               // print each form field’s value
               print( "<td>$fname $lname</td>
                  <td>$email</td>
                  <td>$phone</td>
                  <td>$os</td>" );
            ?>
         </tr>
      </table>
   
      <br /><br /><br />
      <div style = "font-size: 10pt; text-align: center">
         This is only a sample form. 
         You have not been added to a mailing list.
      </div>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
Arrays

<html>
   <head>
      <title>Array manipulation</title>
   </head>
   <body>
      <?php
         // create array first
         print( "<strong>Creating the first array</strong>
            <br />" );
         $first[ 0 ] = "zero";
         $first[ 1 ] = "one";
         $first[ 2 ] = "two";
         $first[] = "three";
 
         // print each element’s index and value
         for ( $i = 0; $i < count( $first ); $i++ ) 
            print( "Element $i is $first[$i] <br />" );
   
         print( "<br /><strong>Creating the second array
            </strong><br />" );
         // call function array to create array second 
         $second = array( "zero", "one", "two", "three" );
         for ( $i = 0; $i < count( $second ); $i++ ) 
            print( "Element $i is $second[$i] <br />" );
   
         print( "<br /><strong>Creating the third array
            </strong><br />" );
         // assign values to non-numerical indices 
         $third[ "Harvey" ] = 21;
         $third[ "Paul" ] = 18;
         $third[ "Tem" ] = 23;
         // iterate through the array elements and print each 
         // element’s name and value
         for ( reset( $third ); $element = key( $third ); 
            next( $third ) ) 
            print( "$element is $third[$element] <br />" );
   
         print( "<br /><strong>Creating the fourth array
            </strong><br />" );
         // call function array to create array fourth using
         // string indices
         $fourth = array(  
            "January"   => "first",   "February" => "second",
            "March"     => "third",   "April"    => "fourth",
            "May"       => "fifth",   "June"     => "sixth",
            "July"      => "seventh", "August"   => "eighth",
            "September" => "ninth",   "October"  => "tenth",
            "November"  => "eleventh","December" => "twelfth"
            );
         // print each element’s name and value
         foreach ( $fourth as $element => $value ) 
            print( "$element is the $value month <br />" );
      ?>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
Shopping Cart

Shopping Cart - Part 1

<html>
   <head><title>Shopping Cart</title></head>
   <body>
      <?php 
         if ( !( $file = fopen( "catalog.txt", "r" ) ) )
            die( "The database could not be opened. </body>
                  </html>\n" );
      ?>
      <h1 style = "text-align: center">
         Books available for sale</h1>
      <table border = "1" cellpadding = "7" align = "center">
         <tr><th>Name</th><th>Year</th><th>ISBN</th>
             <th>Price</th></tr>
         <?php
            while ( !feof( $file ) ) {
               $line = fgets( $file, 255 );
      
               $data = split( "\t", $line );
               print( "<form method = \"post\" 
                       action = \"cart.php\">
                       <input type = \"hidden\" name =
                       \"REMOVE\" value = \"0\" />
                       <input type = \"hidden\" name = 
                       \"NEWBOOK\" value = \"$line\" /><tr>" );
 
               foreach ( $data as $key => $value )
                  print( "<td>$value</td>" );
      
               print( "<td><input type = \"submit\" 
                       value = \"Buy\" />
                       </td></tr></form>" );
            }
            fclose( $file );
         ?>
      </table>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
Shopping Cart - Part 2

<?php 
   // Fig. 29.27: cart.php
   // Add or remove a book from cart and print contents
   if ( $REMOVE > 0 ) {
      $books = split( "\t", $CART );
      array_splice( $books, ( $REMOVE - 1 ) * 4, 4 );
      $new = join( $books, "\t" );
      setcookie( "CART", $new, time() + 60 * 60 * 24 * 5 );
   }   
   else {
      if ( isset( $CART ) )
         $new = $CART . "\t" . $NEWBOOK;
      else 
         $new = $NEWBOOK;
      
      setcookie( "CART", $new );
      
      $title = split( "\t", $NEWBOOK );
      print( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 
              1.0 Transitional//EN\"
              \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
              transitional.dtd\">
              <html xmlns=\"http://www.w3.org/1999/xhtml\">
              <head><title>Book Added</title></head>
              <body><div style = \"text-align: center\">
              The book <em>" .$title[0]. "</em>
              has been added to your cart." );
   }
?>
      <p style = "text-align: center">
         Here is your current order.</p>
      <table border = "1" cellpadding = "7" align = "center">
         <tr>
            <th>Item</th>
            <th>Name</th><th>Year</th><th>ISBN</th>
            <th>Price</th><th></th>
         </tr>
         <?php
            $total = 0;
            $book = split( "\t", $new );
            for ( $i = 0;  count( $book ) > 1 && 
                  $i < count( $book ); $i += 4 )
            {
               $item = $i / 4 + 1;
               print( "<tr><form method = \"post\"
                       action = \"cart.php\">
                       <td>" . $item . "</td>
                       <td>" . $book[ $i ] . "</td> 
                       <td>" . $book[ $i+1 ] . "</td>
                       <td>" . $book[ $i+2 ] . "</td>
                       <td>" . $book[ $i+3 ] . "</td>
                       <td><input type = \"submit\" 
                       value = \"Remove\" /></td>
                       <input type = \"hidden\" name = 
                       \"REMOVE\" value = \"$item\" />
                       </form></tr>" );
      
               $price = substr( $book[ $i + 3 ], 1 );
               $total += doubleval( $price );
            }
   
            print( "<tr><th colspan = \"4\">Total Order</th>" );
            printf( "<th>\$%0.2f", $total );
            print( "</th></tr>" );
         ?>
      </table><br />
      <p style = "text-align: center">
      <a href = "books.php">Buy more books</a></p>
   </body>
</html>
-----------------------------------------------------------------------------------------------------
Shopping Cart - Text
Visual Basic 6 How to Program	1999	0-13-456955-5	$50.00
C++ How to Program	1997	0-13-528910-6	$49.95
C How to Program	1994	0-13-226119-7	$50.00
Java How to Program	1997	0-13-899394-7	$39.95
Java How to Program 2e	1999	0-13-012507-5	$50.00
-----------------------------------------------------------------------------------------------------
Comparisons Using an Array

<html>
   <head>
      <title>String Comparison</title>
   </head>
   <body>
      <?php 
         // create array fruits
         $fruits = array( "apple", "orange", "banana" );
      
         // iterate through each array element
         for ( $i = 0; $i < count( $fruits ); $i++ ) {
            // call function strcmp to compare the array element
            // to string "banana"
            if ( strcmp( $fruits[ $i ], "banana" ) < 0 )
               print( $fruits[ $i ]." is less than banana " );
            elseif ( strcmp( $fruits[ $i ], "banana" ) > 0 ) 
               print( $fruits[ $i ].
                  " is greater than banana " ); 
            else 
               print( $fruits[ $i ]." is equal to banana " );
         
            // use relational operators to compare each element
            // to string "apple"
            if ( $fruits[ $i ] < "apple" ) 
              print( "and less than apple! <br />" );
            elseif ( $fruits[ $i ] > "apple" ) 
              print( "and greater than apple! <br />" );
            elseif ( $fruits[ $i ] == "apple" ) 
               print( "and equal to apple! <br />" );
         
         }
      ?>
   </body>
</html>
--------------------------------------------------------------------------------------------------------------
Passwords

Passwords - HTML Document:

<html>
   <head>
      <title>Verifying a username and a password.</title>
      <style type = "text/css">
         td { background-color: #DDDDDD }
      </style>
   </head>
   <body style = "font-family: arial">
      <p style = "font-size: 13pt">
         Type in your username and password below.
         <br />
         <span style = "color: #0000FF; font-size: 10pt;
            font-weight: bold">
            Note that password will be sent as plain text
         </span>
      </p>
      <!-- post form data to password.php -->
      <form action = "password.php" method = "post">
         <br />
   
         <table border = "0" cellspacing = "0" 
            style = "height: 90px; width: 123px; 
            font-size: 10pt" cellpadding = "0">
            <tr>
               <td colspan = "3"> 
                  <strong>Username:</strong>
               </td>
            </tr>
            <tr>
               <td colspan = "3">
                  <input size = "40" name = "USERNAME" 
                     style = "height: 22px; width: 115px" />
               </td>
            </tr>
            <tr>
               <td colspan = "3">
                  <strong>Password:</strong>
               </td>
            </tr>
            <tr>
               <td colspan = "3">
                  <input size = "40" name = "PASSWORD" 
                     style = "height: 22px; width: 115px" 
                     type = "password" />
               <br/></td>
            </tr>
            <tr>
               <td colspan = "1">
                  <input type = "submit" name = "Enter" 
                     value = "Enter" style = "height: 23px; 
                     width: 47px" />
               </td>
               <td colspan = "2">
                  <input type = "submit" name = "NewUser" 
                     value = "New User" 
                     style = "height: 23px" />
               </td>
            </tr>
         </table>
      </form>
   </body>
</html>
----------------------------------------------------------------------------------------------------------------
Passwords - PHP Document

<html>
   <head>
      <?php
         // check if user has left USERNAME 
         // or PASSWORD field blank
         if ( !$USERNAME || !$PASSWORD ) {
            fieldsBlank();
            die();
         }
         // check if the New User button was clicked
         if ( isset( $NewUser ) ) {
            // open password.txt for writing using append mode
            if ( !( $file = fopen( "password.txt", 
               "append" ) ) ) {
               // print error message and terminate script 
               // execution if file cannot be opened
               print( "<title>Error</title></head><body>
                 Could not open password file
                 </body></html>" );
               die();
            }
      
            // write username and password to file and 
            // call function userAdded
            fputs( $file, "$USERNAME,$PASSWORD\n" );
            userAdded( $USERNAME );
         }
         else {
            // if a new user is not being added, open file
            // for reading
            if ( !( $file = fopen( "password.txt", 
               "read" ) ) ) {
               print( "<title>Error</title></head>
                  <body>Could not open password file
                  </body></html>" );
               die();
            }
            $userVerified = 0;
            // read each line in file and check username
            // and password
            while ( !feof( $file ) && !$userVerified ) {
               // read line from file
               $line = fgets( $file, 255 );
     
               // remove newline character from end of line
               $line = chop( $line );
               // split username and password
               $field = split( ",", $line, 2 );
   
               // verify username
               if ( $USERNAME == $field[ 0 ] ) {
                  $userVerified = 1;
   
                  // call function checkPassword to verify
                  // user’s password
                  if ( checkPassword( $PASSWORD, $field ) 
                     == true )
                     accessGranted( $USERNAME );
                  else   
                     wrongPassword();
               }
            }
   
            // close text file
            fclose( $file );
   
            // call function accessDenied if username has 
            // not been verified
            if ( !$userVerified )
               accessDenied();
         }
          // verify user password and return a boolean
         function checkPassword( $userpassword, $filedata )
         {
            if ( $userpassword == $filedata[ 1 ] )
               return true;
            else
               return false;
         }
          // print a message indicating the user has been added
         function userAdded( $name ) 
         {
            print( "<title>Thank You</title></head>
               <body style = \"font-family: arial; 
               font-size: 1em; color: blue\"> 
               <strong>You have been added 
               to the user list, $name.
               <br />Enjoy the site.</strong>" );
         }
          // print a message indicating permission 
          // has been granted
         function accessGranted( $name )
         {
            print( "<title>Thank You</title></head>
               <body style = \"font-family: arial;
               font-size: 1em; color: blue\">
               <strong>Permission has been 
               granted, $name. <br />
               Enjoy the site.</strong>" );
         }
          // print a message indicating password is invalid
         function wrongPassword()
         {
            print( "<title>Access Denied</title></head>
               <body style = \"font-family: arial; 
               font-size: 1em; color: red\">
               <strong>You entered an invalid 
               password.<br />Access has 
               been denied.</strong>" );
         }
          // print a message indicating access has been denied
         function accessDenied()
         {
            print( "<title>Access Denied</title></head>
               <body style = \"font-family: arial; 
               font-size: 1em; color: red\">
               <strong>
               You were denied access to this server.
               <br /></strong>" );
         } 
          // print a message indicating that fields 
          // have been left blank
         function fieldsBlank()
         {
            print( "<title>Access Denied</title></head>
               <body style = \"font-family: arial; 
               font-size: 1em; color: red\">
               <strong>
               Please fill in all form fields.
               <br /></strong>" );
         } 
      ?>
   </body>
</html>
-------------------------------------------------------------------------------------------------------------
Passwords - Text Document

account1,password1
account3,password3
account4,password4
account2,password2
account5,password5
account6,password6
account7,password7
account8,password8
account9,password9
account10,password10
-------------------------------------------------------------------------------------------------------------
Mythical Database Using SQL

Database HTML Document:
<html>
   <head>
      <title>Sample Database Query</title>
   </head>
   <body style = "background-color: #F0E68C">
      <h2 style = "font-family: arial color: blue">
         Querying a MySQL database.
      </h2>
      <form method = "post" action = "database.php">
         <p>Select a field to display:
            <!-- add a select box containing options --> 
            <!-- for SELECT query                    -->
            <select name = "select">
               <option selected = "selected">*</option>
               <option>ID</option>
               <option>Title</option>
               <option>Category</option>
               <option>ISBN</option>
            </select>
         </p>
         <input type = "submit" value = "Send Query" 
            style = "background-color: blue; 
            color: yellow; font-weight: bold" />
      </form>
   </body>
</html>
-------------------------------------------------------------------------------------------------------
Database - PHP Document

<html>
   <head>
      <title>Search Results</title>
   </head>
   <body style = "font-family: arial, sans-serif" 
      style = "background-color: #F0E68C">
      <?php
         // build SELECT query
         $query = "SELECT " . $select . " FROM Books";
         // Connect to MySQL
         if ( !( $database = mysql_connect( "localhost", 
            "httpd", "" ) ) )
            die( "Could not connect to database" );
   
         // open Products database
         if ( !mysql_select_db( "Products", $database ) )
            die( "Could not open Products database" );
   
         // query Products database
         if ( !( $result = mysql_query( $query, $database ) ) ) {
            print( "Could not execute query! <br />" );
            die( mysql_error() );
         }
      ?>
      <h3 style = "color: blue"> 
      Search Results</h3>
      <table border = "1" cellpadding = "3" cellspacing = "2"
         style = "background-color: #ADD8E6">
         <?php
            // fetch each record in result set
            for ( $counter = 0; 
               $row = mysql_fetch_row( $result );
               $counter++ ){
               // build table to display results
               print( "<tr>" );
               foreach ( $row as $key => $value ) 
                  print( "<td>$value</td>" );
               print( "</tr>" );
            }
            mysql_close( $database );
         ?>
      </table>
      <br />Your search yielded <strong>
      <?php print( "$counter" ) ?> results.<br /><br /></strong>
      <h5>Please email comments to
         <a href = "mailto:huh@question.com">
            Huh?
         </a>
      </h5>
   </body>
</html>
--------------------------------------------------------------------------------------------------------