How to use the session when verifying management landing

Source: Internet
Author: User
Tags add end sql reset table name
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>
&LT;TD width= "129" > </td>
&LT;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>
&LT;TD colspan= "2" ><div align= "right" ></div></td>
</tr>
</table>
</form>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.