#
# 表的結構 `admin`
#
#
# 導出表中的數據 `admin`
#
insert into `admin` (`id`, `us`, `pas`) values (1, 'admin', 'admin');
*/?>
登錄html頁面代碼
代碼如下 復制代碼<html>
<head>
<title>登錄</title>
<meta http-equiv="content" content="text/html; charset=gb2312">
<link href="css教程.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
if ($http_cookie_vars["admin"]) {
header("location:admin.php");
}
?>
<form method="post" action="admin_logins.php">
<table width="40%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolorlight="#cccccc" bordercolordark="#f7f7f7" class="css">
<tr>
<td bgcolor="#f7f7f7" colspan="2" align="center"><b>管理員登錄</b></td>
<tr>
<tr>
<td>用戶名</td>
<td><input type="text" name="us" size="30" maxlength="30" class="inputt"></td>
<tr>
<tr>
<td>密碼</td>
<td><input type="password" name="pas" size="34" class="inputt" maxlength="40"></td>
</tr>
<tr>
<td bgcolor="#f7f7f7" colspan="2"><div align="center">
<input type="submit" name="submit" class="inputt" value="進入">
</div></td>
</tr>
</table>
</form>
</body>
</html>
php代碼
代碼如下 復制代碼<?php
$db=@mysql_connect("localhost","root","micronsky.net") or die("數據庫連接也錯");
mysql_select_db("vote",$db);
$submit=$_post["submit"];
$us=$_post["us"];
$pas=$_post["pas"];
if ($submit) {
$result=mysql_query("select us,pas from admin where us='$us'",$db);
if ($myrow=mysql_fetch_array($result)) {
if ($pas==$myrow["pas"]) {
setcookie("admin",$us,time()+3600);
header("location:admin.php");
}
else {
echo "<script>alert('密碼不正確');history.back();</script>";
}
}
else {
echo "<script>alert('用戶名不存在');history.back();</script>";
}
}
?>