Managing the Login
May 24, 2002
The next section of code we are going to examine covers the user's logging in to and out of the application. This code is contained in the chapter5_login.php file. The code starts out by starting a session for the user if they don't already have one. Next, it establishes sessiondata as the variable that should be tracked. Before prompting the user for login information, it invalidates any previous login that may exist by setting the login name to NULL. This prevents the user from going directly to a page in the application and bypassing the entry page.
chapter5_login.php
<?php session_start(); session_register("sessiondata"); $sessiondata[username] = NULL;
After you have established the user's session data, you then check to see whether this script was called with a logout action, such as chapter5_login.php?action=logout. When the application directs the user to this screen, it passes the logout action to indicate that the user plans to exit the application, as shown here:
//Retrieve input variables from HTTP get or post $userinfo = strtolower($REQUEST_METHOD) == 'get' ? $HTTP_GET_VARS : $HTTP_POST_VARS;
if ($userinfo[action] == 'logout') { echo "<CENTER>\n"; echo "<BR><BR><BR>\n"; echo "You have been logged out of the MySQL Database\n"; echo "<BR><BR><BR>\n"; echo "<A HREF=\"chapter5_login.php\">Click Here To Log "; echo "In Again</A>\n"; echo "</CENTER>\n"; }
If the action of logout is not included in the page request, the user will be prompted to log in to the application, as follows:
else { echo "<!doctype html public \""; echo "-//W3C//DTD HTML 4.0 //EN\">\n"; echo "<HTML>\n"; echo "<HEAD>"; echo "<TITLE>Instant PHP4 Chapter5 - "; echo "Database Administration</TITLE>\n"; echo "</HEAD>\n"; echo "<CENTER>\n"; echo "<BODY>\n"; echo "Chapter5 - Database Administration - Login\n"; echo "<BR><BR><BR>\n"; echo "<FORM ACTION=\"chapter5_dbMonitor.php\"\n"; echo "METHOD=\"POST\">\n"; echo "<TABLE CELLSPACING=5 CELLPADDING=5 BORDER=3 "; echo "BORDERCOLOR=\"0000FF\" >\n"; echo "<TR><TD>\n"; echo "Username</TD><TD><INPUT TYPE=\"TEXT\" NAME=\""; echo "in_username\" SIZE=\"30\" MAXLENGTH=\"16\" "; echo "SELECTED=TRUE><BR>\n"; echo "</TD></TR>\n"; echo "<TR><TD>\n"; echo "Password</TD><TD><input type=\"password\" name=\""; echo "in_password\" SIZE=\"30\"><BR>\n"; echo "</TD></TR>\n"; echo "<TR><TD>\n"; echo "Hostname</TD><TD><input type=\"text\" name=\""; echo "in_hostname\" SIZE=\"30\"><BR>\n"; echo "</TD></TR>\n"; echo "</TABLE>\n"; echo "<BR><BR>\n"; echo "<INPUT TYPE=\"SUBMIT\" VALUE=\"Login\">\n"; echo "   \n"; echo "<INPUT TYPE=\"RESET\" VALUE=\"Reset\">\n"; echo "</FORM>\n"; echo "</CENTER>\n"; echo "</BODY>\n"; echo "</HTML>\n"; } ?>
Display One-Dimensional Array
Instant PHP 4
Database Monitoring
|