Specifications
<body>
<h1>Home page</h1>
<?
if (session_is_registered(“valid_user”))
{
echo “You are logged in as: $valid_user <br>”;
echo “<a href=\”logout.php\”>Log out</a><br>”;
}
else
{
if (isset($userid))
{
// if they’ve tried and failed to log in
echo “Could not log you in”;
}
else
{
// they have not tried to log in yet or have logged out
echo “You are not logged in.<br>”;
}
// provide form to log in
echo “<form method=post action=\”authmain.php\”>”;
echo “<table>”;
echo “<tr><td>Userid:</td>”;
echo “<td><input type=text name=userid></td></tr>”;
echo “<tr><td>Password:</td>”;
echo “<td><input type=password name=password></td></tr>”;
echo “<tr><td colspan=2 align=center>”;
echo “<input type=submit value=\”Log in\”></td></tr>”;
echo “</table></form>”;
}
?>
<br>
<a href=”members_only.php”>Members section</a>
</body>
</html>
Some reasonably complicated logic is in this script because it displays the login form, and is
also the action of the form.
Using Session Control in PHP
C
HAPTER 20
20
USING SESSION
C
ONTROL IN
PHP
441
LISTING 20.4 Continued
25 7842 CH20 3/6/01 3:42 PM Page 441










