Creating Password Controls


Here's another useful type of HTML controlpassword controls. From a PHP point of view, these controls work just like text fields; but they're different from the user's point of view. The user sees only asterisks (*) each time he or she types a key instead of letters, so this control is handy for reading passwords and other sensitive data.

You can see an example, phppassword.html, in Example 5-13. This example asks the user what the password is by using a password control.

Example 5-13. Using password controls, phppassword.html
 <HTML>     <HEAD>         <TITLE>             Using Password Controls         </TITLE>     </HEAD>     <BODY>         <CENTER>             <H1>                 Using Password Controls             </H1>             <FORM METHOD="POST" ACTION="phppassword.php">                 What's the password?                 <INPUT NAME="Password" TYPE="PASSWORD">                 <BR>                 <BR>                 <INPUT TYPE="SUBMIT" VALUE=Submit>             </FORM>         </CENTER>     </BODY> </HTML> 

You can see what this page looks like in Figure 5-13, where the user has already typed in a password (which in this case is "Open sesame") into a password control named Password.

Figure 5-13. Using a password control.


Although you can't read the password when you type it in, the password is available to your PHP code. Use $_REQUEST["Password"], as you see in phppassword.php, Example 5-14.

Example 5-14. Retrieving data from password controls, phppassword.php
 <HTML>     <HEAD>         <TITLE>             Retrieving Password Data         </TITLE>     </HEAD>     <BODY>         <CENTER>             <H1>                 Retrieving Password Data             </H1>             You entered:             <BR>             <?php                 echo $_REQUEST["Password"];             ?>         </CENTER>     </BODY> </HTML> 

The result appears in Figure 5-14, where we've been successful in reading the data from the password control. As you'd expect, in a real application, you'd want to check the password against a password list and deny access unless it checks out.

Figure 5-14. Reading data from a password control.




    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net