Anda di halaman 1dari 4

ASP Lab Guide 6 T0410I

120 pht tip Step by step


Hng dn lm phn Admin Login trong ASP
Buc 1: -To CSDL MobileShop trong SQL Server -To bng admin

-Vit nhng cu truy vn insert d liu vo bng trn Cho bng admin ID 1 2 Username admin yourname Password admin yourpass

Bc 2: -To th mc MobileShop trong wwwroot -Trong th mc MobileShop to mt th mc con tn l Images cha nh ca sn phm -To site tn l MobileShop trong DreamWeaverMX (ASP Javascript, th mc gc l MobileShop) Bc 3: -Copy nh sn phm vo th mc Images -To cc file nh hng dn di y v lu vo th mc MobileShhop

1. Kt ni ti CSDL (Connection.asp) -u tin to bn phi to file Connection.asp sau save vo th mc includes trong th mc MobileShop -File ny cha tt c cc thng tin kt ni ti CSDL ca bn. -Cc file khc trong ng dng ca bn phi include ti file Connection.asp to ra s kt ni ti CSDL -Chng ta s dng connection ti SQL Server, cc bn c th nghin cu thm v vic dng Access Ni dung ca file Connection.asp nh sau: <!-- Creating Connection To Database --> <% var oConn; // Khi to i tng kt ni v to kt ni ADO ti CSDL SQL Server Authors oConn = Server.CreateObject("ADODB.Connection"); oConn.Open("Provider=SQLOLEDB;Server=ten_server;Database=MobileShop;UID=sa;PWD=sa"); // Khi to i tng kt ni v to kt ni ADO ti CSDL Access Authors // nh x CSDL Access authors thnh mt ng dn vt l //var filePath; //filePath = Server.MapPath("authors.mdb"); //oConn = Server.CreateObject("ADODB.Connection"); //oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +filePath);

%>

2.Hin th trang login (LoginForm.asp) -Trang ny hin form login admin login
Ni dung ca file LoginForm.asp nh sau: <%@language=JavaScript %> <!-- #include file="includes/Connection.asp" --> <html> <head> <title> Login </title> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <font face="arial"> <center> <table> <td valign=top align=right> <font face="helvetica" size="6"> <br> <p align="left"> <br> <br> <font face="helvetica" size="2"> <b><%= Request.QueryString("msg") %></b><br>

<font face="helvetica" size="2"> <form action="LoginVerify.asp" method="post"> <table width=500 border=0> <tr> <td align="right"><font face="helvetica" size="2"> <b>User:</b> </td> <td align="left"><font face="helvetica" size="2"> <input type="text" name="username" value="" size="12"> </td> </tr> <tr> <td align="right"><font face="helvetica" size="2"> <b>Password:</b> </td> <td align="left"><font face="helvetica" size="2"> <input type="password" name="password" value="" size="12"> </td> <tr> <td align="left" colspan=2> <font face="helvetica" size="2"> </tr> </table> <input type="submit" name="submit" value="Login"> </form> </td> </table> <br><br> </body> </html>

3.Trang x l thng tin login (LoginVerify.asp) -Trang ny x l thng tin login, nu hp l th s chuyn hng sang trang dnh cho admin, nu khng s thng bo li Ni dung trang LoginVerify.asp nh sau: <%@language=JavaScript %>
<!-- #include file="includes/Connection.asp" -->

<% var username = Request.Form("username"); var password = Request.Form("password"); var strSQL = "select * from admin where username=' " + username + " ' and password =' " + password + " "; var rsVerify = oConn.Execute(strSQL); if (rsVerify.EOF) { oConn.Close(); Response.Redirect("LoginForm.asp?msg=" + Server.URLEncode("Sai email hoc passowd")); } //Neu login thanh cong se lay thng tin cua Admin de da vao session va chuyen huong sang trang //adminpage Session("AdminID") = rsVerify.fields("id").value; Session("Username") = rsVerify.fields("username").value; rsVerify.Close(); oConn.Close(); Response.Redirect("AdminPage.asp"); %>

4.Trang dnh cho Admin (AdminPage.asp) -Trang ny dng hin th thng tin dnh cho admin, nu bn cha ng nhp th s chuyn hng v trang ng nhp <%@language=JavaScript %> <!--#include file="includes/Connection.asp"--> <% //Check if admin is logined in if ((Session("AdminID") == null) || (Session("AdminID") == "")) { Response.Redirect("LoginForm.asp"); } Response.Write("You are logined as Admin!"); Response.Write("<br><br>Click here to <a href="Logout.asp">logout</a>"); %> 4.Trang dnh cho Logout (Logout.asp) -Trang ny dng logout, n s hy b session ca Admin, hy b thng tin ng nhp ca admin <%@language=JavaScript %> <!--#include file="includes/Connection.asp"--> <% Session("AdminID") = ""; Response.Redirect("LoginForm.asp"); %>

Anda mungkin juga menyukai