Õâ¸öphpÊý¾Ý¿âÄÄÀï³öÎÊÌâÁË£¿
<?session_start();
if ($profid && $profpw)
{
// if the user has just tried to log in
$db_conn = mysql_connect("prof","prof");
mysql_select_db("physics_labs");
$query = "select * from profinfo"
."where profid='$profid'"
." and profpw='$profpw'";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_prof = $profid;
session_register("valid_prof");
}
}
?>
<html>
<body>
<h1>Teachers' login page</h1>
<?
if (session_is_registered("valid_prof"))
{
echo "You are logged in as: $valid_prof <br>";
echo "<a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($profid))
{
// if they've tried and failed to log in
echo "User not exist or Password is not correct!";
}
else
{
// You 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=\"profauth.php\">";
echo "<table>";
echo "<tr><td>Teacher's ID:</td>";
echo "<td><input type=text name=profid></td></tr>";
echo "<tr><td>Password:</td>";
echo "<td><input type=password name=profpw></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>
ÔõôÎÞÂÛÈçºÎ²»ÄÜÕýÈ·ÑéÖ¤Óû§£¿ ÄãµÄÓû§ÃûºÍÃÜÂëµÄ±äÁ¿´«µÝÈ·¶¨È¡µ½ÁËֵûÓУ¿Èç¹ûphp.iniÖеÄregister_gloablûÓдò¿ªµÄ»°£¬ÐèÒªÓÃ$_GETÈ¡´«µÝµÄ±äÁ¿Öµ
Ò³:
[1]