還是跟着昨天的,用戶管理這一塊!
今天是註銷,通過跟蹤session會話來保存用戶的登陸狀態!!
login.php頁面代碼
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>用戶登錄</title></head>
<body>
<center>
<table width=50% border=1>
<form action=loginchk.php method=post>
<tr>
<td>
<div align=center><strong>用戶登陸</strong>
</div>
<hr>
<p align=center>請輸入你的用戶名:
<input type=text name=username></p>
<p align=center>請輸入你的密碼:
<input type=password name=pwd></p>
<div align=center>
<input type=submit value=提交>
<input type=reset value=清除>
</div>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>用戶登錄</title></head>
<body>
<center>
<table width=50% border=1>
<form action=loginchk.php method=post>
<tr>
<td>
<div align=center><strong>用戶登陸</strong>
</div>
<hr>
<p align=center>請輸入你的用戶名:
<input type=text name=username></p>
<p align=center>請輸入你的密碼:
<input type=password name=pwd></p>
<div align=center>
<input type=submit value=提交>
<input type=reset value=清除>
</div>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
簡單的登陸界面,POST數據到loginchk.php頁面進行用戶驗證
loginchk.php代碼
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>登陸用戶的執行結果</title></head>
<body>
<center>
<?php
$name = $_POST['username'];
$pwd = $_POST['pwd']; //這邊都知道,獲取傳送過來的用戶名和密碼
$link = mysql_connect("localhost","root","wutianshen");
if(!$link){
echo "數據庫連接失敗!";
mysql_error();
} //連接數據庫,多寫一個mysql_errro()絕對有好處,讓你知道在數據庫連接上有沒有出錯及出錯信息!
mysql_select_db("user");
$exec = "SELECT * FROM myuser WHERE lname='$name'"; //sql語句,查詢用戶名稱!
$result = mysql_query($exec);
$rows = mysql_num_rows($result);
if($rows>0){
$row = mysql_fetch_assoc($result);
$lname=$row['lname'];
$rname=$row['rname'];
$lpwd=$row['lpwd'];
if($lpwd==$pwd){
session_start();
$_SESSION['olname']=$lname;
$_SESSION['olrname']=$rname; //上面幾段就是密碼效驗,都比較簡單,哈哈!~
echo "用戶登陸成功!";
echo "<hr><p>登陸用戶是:".$rname."<p>";
echo "<br>現在你可以<a href=usercenter.php>轉到用戶中心</a>";
}else{
echo "用戶登陸失敗!<hr><p>";
echo "用戶名或密碼不正確!!";
echo "<br><a href=login.php>請重新登陸</a>";
}
}else{
echo "用戶登陸失敗!<hr><p>";
echo "當前用戶不存在!";
echo "<br><a href=adduser.php>請先註冊,再進行登陸!</a>";
}
?>
</center>
</body>
</html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>登陸用戶的執行結果</title></head>
<body>
<center>
<?php
$name = $_POST['username'];
$pwd = $_POST['pwd']; //這邊都知道,獲取傳送過來的用戶名和密碼
$link = mysql_connect("localhost","root","wutianshen");
if(!$link){
echo "數據庫連接失敗!";
mysql_error();
} //連接數據庫,多寫一個mysql_errro()絕對有好處,讓你知道在數據庫連接上有沒有出錯及出錯信息!
mysql_select_db("user");
$exec = "SELECT * FROM myuser WHERE lname='$name'"; //sql語句,查詢用戶名稱!
$result = mysql_query($exec);
$rows = mysql_num_rows($result);
if($rows>0){
$row = mysql_fetch_assoc($result);
$lname=$row['lname'];
$rname=$row['rname'];
$lpwd=$row['lpwd'];
if($lpwd==$pwd){
session_start();
$_SESSION['olname']=$lname;
$_SESSION['olrname']=$rname; //上面幾段就是密碼效驗,都比較簡單,哈哈!~
echo "用戶登陸成功!";
echo "<hr><p>登陸用戶是:".$rname."<p>";
echo "<br>現在你可以<a href=usercenter.php>轉到用戶中心</a>";
}else{
echo "用戶登陸失敗!<hr><p>";
echo "用戶名或密碼不正確!!";
echo "<br><a href=login.php>請重新登陸</a>";
}
}else{
echo "用戶登陸失敗!<hr><p>";
echo "當前用戶不存在!";
echo "<br><a href=adduser.php>請先註冊,再進行登陸!</a>";
}
?>
</center>
</body>
</html>
請大蝦們多多指教!~~