session|session Novice ASP people to the session has been not very understanding. I'm here to talk about this Cai bird. Simple use of the session when doing a simple background login:
One: login.htm
I'm not going to say much about this page. Add the form to the admin nickname give the text box username
Write the password to give the text box Userpass and then add a Submit button. Note: The action for the form is chklogin.asp
Two: chklogin.asp
<!--#include file= "conn.asp"-->
<%set Rs=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from admin where username= '" &request. Form ("username") & "'"
' where admin is the table name for the storage Administrator account and password
Rs.Open sql,con,1,1
%>
<%if Rs.eof Then
Response. Write "No This Administrator"
Else
%>
<%
Username=trim (Request. Form ("username"))
Password=request. Form ("password")
%>
<%if password=rs ("Userpass") Then
Session ("admin") = "Ercifang"
Response. Redirect ("manage.asp")
Else
Response. Write "This page is the administrator-specific page"
End If
%>
<%end if%>
Look at the red text, so that the administrator added a session
Set the first line in manage.asp
<%if session ("admin") = "Ercifang" Then
......
Else
Response.Write "Only administrators can access this page"
End If%>
In this way, other people directly to visit the manage.asp can not manage the site.
The following login.htm code is given:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Management Login </title>
<style type= "Text/css" >
. fengge{font-size:12px}
</style>
<body>
<form name= "Form1" method= "Post" action= "chklogin.asp" >
<table width= "border=" 1 "align=" center "class=" Fengge ">
<tr>
<TD width= "129" > </td>
<TD width= "255" > </td>
</tr>
<tr>
<td><div align= "Right" > Administrator name:</div></td>
<td><input name= "username" type= "text" id= "username" ></td>
</tr>
<tr>
<td><div align= "Right" > Admin password:</div></td>
<td><input name= "password" type= "password" id= "password" ></td>
</tr>
<tr>
<td><div align= "right" ></div></td>
<td><input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit" value= "reset" >
</td>
</tr>
<tr>
<TD colspan= "2" ><div align= "right" ></div></td>
</tr>
</table>
</form>
</body>