session| Tutorial | 10 days of learning
Previous section: modifying a record
Learning Objectives: The basic session component, summarizing the Response,request component.
First of all, any program that has a membership system will use to detect whether the user has logged in this step. This uses the session component, and we'll look at a code to illustrate it.
<%
Session ("login") = "yes"
%>
The meaning of this sentence is to define a login string variable in the session, with a value of "yes", which can be assigned directly, without the need for a declaration. Is it simple?
If we do the administrator login system, the first is a section of detection is not an administrator:
If is then
Session ("ISAdmin") =yes "
Else
Session ("ISAdmin") = "No"
End If
At the front of each page that requires an administrator to see:
<%
If not session ("isaadmin") = "yes" then
Response.Redirect "Login.htm"
%>
This will not be possible for the average user to open this page. Explain the Response.Redirect, it is the meaning of turn, the back of the "login.htm" is the file to turn. This will not be able to see the subsequent content of the administrator.
The response component basically uses the Response.Write (), and the Response.Redirect () is the function of writing strings and steering respectively.
The request is basically request.form (), Request.QueryString () is the message that receives Post,get method respectively.
Finally, we will create a simple background login management interface, first in the MyWeb directory to create an admin folder, and then we build a database name for Admin.mdb, then we set up a table, the table set two fields Name,password, types are text-typed! Set the primary key at the end of the exit and save as a table name check. You can then enter a record user name: admin, Password: admin. How to set up a database The third day of the beginner's 10-Day Learning ASP Tutorial: The establishment of a database
Below we start to write ASP program, first establish a index.asp (Admin main Interface) program, the code is as follows:
<% @language =vbscript%>
<%if not session ("checked") = "yes" then
Response. Redirect "Login.asp"
Else
%>
<title> Management Interface </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<frameset cols= "167,*" frameborder= "YES" border= "1" framespacing= "1" rows= "*" bordercolor= "#666666" >
<frame name= "Leftframe" scrolling= "Auto" noresize src= "left.asp" >
<frame name= "MainFrame" src= "right.asp" >
</frameset>
<noframes>
<body bgcolor= "#FFFFFF" text= "#000000" >
</body>
</noframes>
<%end if%>
In the above code, you can see the use of the login.asp,left.asp,right.asp program
login.asp://Login System Program
<title> Admin Entrance </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
. topic {font-family: "Song body"; font-size:11pt font-weight:bold; color: #FFFFFF}
. Font {font-family: "XXFarEastFont-Arial"; font-size:10pt font-weight:normal; color: #000000}
. Table {border-color: #666666 black; border-style:solid; border-top-width:1pt; border-right-width:0px; border-bottom- width:1pt; border-left-width:0px}
. text {border:1pt #999999 solid; height:15pt}
-->
</style>
<body text= "#000000" topmargin= "0" bgcolor= "#FFFFFF" >
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" align= "center" height= "100%" >
<tr>
<TD height= "129" valign= "Top" colspan= "3" > </td>
</tr>
<tr>
<TD width= "230" height= "170" valign= "Top" > </td>
<TD valign= "Top" width= "277" >
<table width= "100%" border= "0" cellspacing= "1" cellpadding= "0" height= "100%" bgcolor= "#000000" align= "Center" >
<tr>
<TD align= "center" valign= "Middle" height= "167" >
<form name= "Form1" method= "Post" action= "check.asp" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" height= "100%" >
<tr bgcolor= "#62892C" >
<TD height= "class=" topic "colspan=" 2 ">
<div align= "center" > Admin Entrance <br>
</div>
</td>
</tr>
<tr>
<TD bgcolor= "#87bc3c" colspan= "2" class= "table" >
<div align= "center" > <span class= "Font" > Administrator:</span>
<input type= "text" name= "name" class= "text" size= ">
<br>
<span class= "Font" > Password:</span>
<input type= "password" name= "password" class= "text" size= "the" ><%if session ("check") = "wrong" then response. Write "<br><span class= ' font ' ><font color=red> validation error!</font></span>" End if%>
</div>
</td>
</tr>
<tr>
<TD bgcolor= "#87bc3c" width= "52%" >
<div align= "center" class= "Font" >
<input type= "reset" name= "Submit2" value= "reset" class= "text" >
</div>
</td>
<TD bgcolor= "#87bc3c" width= "48%" >
<div align= "center" class= "Font" >
<input type= "Submit" Name= "Submit22" value= "submitted" class= "text" >
</div>
</td>
</tr>
</table> </form>
</td>
</tr>
</table>
</td>
<TD width= "241" valign= "Top" > </td>
</tr>
<tr>
<TD height= "123" valign= "Top" colspan= "3" > </td>
</tr>
</table>
</body>
Use a program in the above program to check if the user and password are correct check.asp://Check that the user and password entered are correct
<%
Dim Name,password
Name=request.form ("name")
Password=request.form ("password")
Dim exec,conn,rs
exec= "Select *from Check where (name= ' &name&" ' and password= ' "&password& ')"
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Admin.mdb")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open Exec,conn
If not rs.eof then
Rs. Close
Conn. Close
Session ("checked") = "yes"
Session ("check") = ' right '
Response. Redirect "Index.asp"
Else
Session ("checked") = "No"
Session ("check") = "wrong"
Response. Redirect "Login.asp"
End If
%>
left.asp://Manage Navigation
<% @language =vbscript%>
<%if not session ("checked") = "yes" then
Response. Redirect "Login.asp"
Else
%>
<title> Management Interface </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body text= "#000000" topmargin= "0" bgcolor= "#ffffff" leftmargin= "ten" >
<div align= "center" ><a href= "index.asp" target= "_parent" ><br>
<br>
Admin Interface Home </a> <a href= "exit.asp" target= "_parent" > Exit </a><br>
<br>
</div>
</body>
<%end if%>
exit.asp://Exit system
<% @language =vbscript%>
<%
Session ("check") = ""
Session ("checked") = ""
Response.Redirect "Login.asp"
%>
right.asp://Specific management content
<% @language =vbscript%>
<%if not session ("checked") = "yes" then
Response. Redirect "Login.asp"
Else
%>
<title> Management Interface </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#ffffff" text= "#000000" topmargin= "class=" "title" >
Here is the web page teaching network Management System example! Please study and use more!
</body>
<%end if%>
Run Index.asp first run the program, the operating effect of the partial screenshot as follows:
Next section: Paging Technology