|
|
|
code login logout อยากได้ code login logout ของ ASP จัง ตอนนี้กำลังเขียนเว็บ ที่ใช้ ASP อยู่ แต่เขียนไม่ได้รบรวน |
|
|
|
|
|
|
|
ก็ทำหน้าจแห้ใส่ username password จากนั้นก็สร้างหน้าใหม่เพื่อไปรับค่า username password ที่ผู้ใช้ใส่แล้วทำการเปรียบเทียบกับ database ว่ามีผู้ใช้คนนี้หรือไม่ ถ้ามีก็ทำการ login ถ้าไม่มีก็แสดงข้อความ error อ่ะ
ถ้าผิดพลาดต้องขออภัยมา ณ ที่นี่ด้วย
|
|
|
|
|
Date :
22 ส.ค. 2550 09:59:22 |
By :
am_conan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้า Login.asp
<!--#include file="include/connection+.asp" -->
<%
Dim usr, pwd, sql, rs, errmsg,sex
usr = Request.Form("user")
pwd = Request.Form("pwd")
sex = Request.Form("sex")
If usr = "" Or pwd = "" Or sex = "" Then
' ถ้าป้อนข้อมูลไม่ครบถ้วนให้กำหนดค่าว่างให้กับตัวแปร session
Session("user") = ""
End If
If usr <> "" And pwd <> "" Then
On Error Resume Next
' ทำการติดต่อฐานข้อมูล
If ConnectDB() = True Then
sql = "Select username, password " & _
"From admin " & _
"Where username='" & usr & "' And " & _
"password='" & pwd & "' And " & _
"sex='" & sex & "'"
Set rs = Conn.Execute(sql)
If Not rs.EOF Then
' ถ้าพบผู้ใช้ให้ทำการเก็บค่าใส่ตัวแปร session
Session("user") = rs("username")
errmsg = ""
' และไปยังหน้าหลักของหลังร้าน
Response.Redirect "manage.asp"
Else
' ถ้าไม่พบผู้ใช้ให้กำหนดว่าว่างให้กับตัวแปร session
Session("user") = ""
errmsg = "<p align=center><font color=red><b>ล็อกอินไม่ถูกต้อง กรุณาป้อนใหม่อีกครั้ง</b></font></p>"
End If
Else
Response.Write "มีปัญหาในการติดต่อฐานข้อมูล กรุณาติดต่อผู้ดูแลระบบ"
Response.End
End If
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>หน้าล็อกอินเข้าสู่ระบบนักศึกษา</title>
<style type="text/css">
<!--
body,td,th {
font-family: tahoma;
font-size: 14px;
color: #FF0000;
}
a {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: #00CCCC;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
.style1 {
font-size: 16px;
font-weight: bold;
}
-->
</style></head>
<body>
<p>
<% =errmsg %>
</p>
<form name="form1" method="post" action="Login.asp">
<table width="35%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="5%"><img src="images/ขอบ2_01.gif" width="19" height="19"></td>
<td width="88%"><img src="images/ขอบ2_02.gif" width="100%" height="19"></td>
<td width="7%"><img src="images/ขอบ2_03.gif" width="19" height="19"></td>
</tr>
<tr>
<td><img src="images/ขอบ2_04.gif" width="19" height="247"></td>
<td valign="top" background="images/ขอบ2_05.gif"><table width="96%" border="0">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><div align="center" class="style1">กรุณากรอกเพื่อยืนยันสิทธิ์</div></td>
</tr>
<tr>
<td width="30%"> </td>
<td colspan="2"><label for="Submit"></label></td>
</tr>
<tr>
<td><strong>Username</strong></td>
<td colspan="2"><font color="#0099FF" size="5" face="-JS Pranee">
<input name="user" type="text" id="user4" size="20">
</font></td>
</tr>
<tr>
<td><strong>password</strong></td>
<td colspan="2"><font color="#0099FF" size="5" face="-JS Pranee">
<input name="pwd" type="password" id="pwd4" size="20">
</font></td>
</tr>
<tr>
<td> </td>
<td colspan="2"><p>
<label>
<input type="radio" name="sex" value="male">
Male</label>
<br>
<label>
<input type="radio" name="sex" value="female">
Female</label>
<br>
</p></td>
</tr>
<tr>
<td> </td>
<td width="26%"><div align="right">
<input type="submit" name="Submit" value="ตกลง" id="Submit">
</div></td>
<td width="44%"><input type="reset" name="reset" value="เคลีร์ย" id="reset"></td>
</tr>
</table></td>
<td><img src="images/ขอบ2_06.gif" width="19" height="247"></td>
</tr>
<tr>
<td><img src="images/ขอบ2_07.gif" width="19" height="20"></td>
<td><img src="images/ขอบ2_08.gif" width="100%" height="20"></td>
<td><img src="images/ขอบ2_09.gif" width="19" height="20"></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
หน้า connect+.asp
<%
Dim conn
Function ConnectDB()
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("..\Register_Stu\database\dbn.mdb")& ";Jet OLEDB:DataBase Password=student;"
If Err.Number = 0 Then
ConnectDB = True
Else
ConnectDB = False
End If
End Function
%>
หมายเหต ก็เปลี่ยนตรงที่เกี่ยวกับฐานข้อมูลนะครับ
|
|
|
|
|
Date :
18 ต.ค. 2551 11:10:50 |
By :
อาร์ท |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|