Tài liệu Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập pptx

5 760 0
Tài liệu Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập 1. Yêu cầu: - Thiết kế Form đăng nhập (hình trái), cho phép lưu lại tài khoản. Nếu đăng nhập thành công thì mở ra trang Home.asp (hình phải) File Login.asp <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>User name</title> </head> <body> <% 'Kiem tra neu da co Cookies thi dang nhap luon vao trang Home.asp if request.cookies("Acc")("user")="Admin" and request.cookies("Acc")("pass")="12345" then response.redirect("Home.asp") else 'Neu chua co Cookies thi cho hien giao dien dang nhap %> GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập <form method="POST" action="login.asp"> <table border="1" width="56%" id="table1" bgcolor="#C0C0C0"> <tr> <td width="129" height="35"><b>User name</b></td> <td height="35"> <input name="txtUser" size="20"></td> </tr> <tr> <td width="129" height="33"><b>Password</b></td> <td height="33"> <input type="password" name="txtPass" size="19"></td> </tr> GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập <tr> <td colspan="2"> <input type="checkbox" name="chkSave" value="ON"> <b>Remember your account</b> </td> </tr> </table> <input type="submit" value=" Login " name="CmdLogin"> </form> <% 'Neu tai khoan dang nhap chinh xac thi cho vao` trang Home.asp if request.form("txtuser")="Admin" and request.form("txtpass")="12345" then 'Neu check luu lai thong tin ve tai khoan thi tao Cookies de luu if request.form("chkSave")<>"" then 'Tao Cookies luu lai tai` khoan response.cookies("Acc")("User")="Admin" response.cookies("Acc")("pass")="12345" 'Dat thoi han ton tai cua Cookies la 5 ngay ke tu ngay hien tai response.cookies("Acc").expires=date()+5 end if response.redirect("Home.asp") else 'Tai khoan dang nhap khong chinh xac thi bao loi if request.form("cmdLogin")<>"" then response.write "Login error !" end if end if end if %> </body> </html> File Home.asp <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Login successfull</title> </head> <body> <p><b>Login successful !</b></p> <form method="POST" action="Home.asp"> <p>Do you want <input type="submit" value="Logout" name="cmdLogout"></p> </form> <% 'Nhan Logout de huy Cookies if request.form("cmdLogout")<>"" then GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập response.cookies("Acc")("user")="" response.cookies("Acc")("pass")="" 'Khong dung` Expires thi Cookies se bi huy 'ngay sau khi dong IE hien hanh` response.redirect("Login1.asp") end if %> </body> </html> 3. Nâng cấp chương trình: Yêu cầu kiểm tra tài khoản đang nhập có tồn tại trong CSDL không. Làm theo các bước sau: (1) Tạo CSDL HOSO.MDB và bảng Account(ID(Autonumber), User(Text), Pass(Text)) (2) Viết file Connection.inc kết nối tới CSDL Connection.inc <% Set Conn=Server.CreateObject("ADODB.Connection") FilePath= Server.Mappath("Hoso.mdb") StrConn="Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & FilePath Conn.Open StrConn Set RS=Server.CreateObject("ADODB.Recordset") %> (3) Chèn đoạn mã sau đây vào trước thẻ <HTML> trong file Login.asp <!--#include file=Connection.inc--> <% ID=request.cookies("Acc")("user") PWD=request.cookies("Acc")("Pass") 'Mo bang du lieu Account va chon ra dung TK da luu trong Cookies StrSQL="Select * from Account Where (User='" & ID & "')AND(Pass='" & PWD & "')" RS.Open StrSQL,Conn %> (4) Sửa lại dòng gạch chân sau thẻ <BODY> như sau: <% 'Kiem tra neu da co Cookies thi dang nhap luon vao trang Home.asp If not rs.eof then response.redirect("Home.asp") else 'Neu chua co Cookies thi cho hien giao dien dang nhap %> ************************************************** GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập 2. Thiết kế website như sau Yêu cầu cho phép: - Đếm số lượt người đã truy cập - Hiển thị ảnh quảng cáo ngẫu nhiên Yêu cầu: Sử dụng file Global.asa (Ghi chú: Chuẩn bị sẵn 3 ảnh: 1.gif, 2.gif, 3.gif) File Global.asa <OBJECT ID="Dem" RUNAT="Server" SCOPE="Application" PROGID="MSWC.Counters"> </OBJECT> <OBJECT ID="Pic" RUNAT="Server" SCOPE="Application" PROGID="MSWC.Adrotator"> </OBJECT> File Quangcao.asp <% response.write "So luot ttruy cap website la:" %> <% dem.Increment("k") response.write dem.get("k") %> <br> <% =pic.GetAdvertisement("quangcao.txt") ‘noi dung file quangcao.txt nhu tren %> GV: LÊ ANH TÚ - Bộ môn Mạng & Truyền thông – Khoa CNTT ĐH Thái Nguyên File Quangcao.txt REDIRECT /login.asp WIDTH 300 HEIGHT 300 BORDER 1 * 1.gif http://home.vnn.vn Trang chu Viet Nam 60 2.gif http://vbcode.com Ma nguon VB 40 3.gif http://www.vnexprepss.net Trang tin tuc 20 . Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập 1. Yêu cầu: - Thiết kế Form đăng nhập (hình trái), cho phép lưu lại tài khoản Bộ môn Mạng & Truy n thông – Khoa CNTT ĐH Thái Nguyên Bài thực hành số 2: Tk Form đăng nhập, ảnh quảng cáo, số lượt đã truy cập < ;form method="POST"

Ngày đăng: 25/12/2013, 23:18

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan