Background Management logon-asp design and database

Source: Internet
Author: User

It is not difficult to implement functions. It is difficult to complete or even perfect.
Therefore, I will post the function implementation and discuss it with beginners. As for perfection, let's look at your own ideas.

1. Create a database

At the beginning, I created a database named windsn. mdb, which contains four tables.
Admin table (for administrator information): id, name (username), pwd (password ),...
Concent table (used to store document data): con_id, title, author, part, con, time, num
Automatic con_id ID
Title article title
Author or source of author
Part document category
Con article content
Time posting time (with = now () as the initial value)
Num times of reading
Part table (used to store classified document data): id, part (category), num
Reply table (for document comment): con_id, rep_id, rep_name, rep_con, rep_time
The field corresponding to the con_id field in the concent table, numeric type
Automatic rep_id ID
Rep_name: username used for comments
Rep_con comments
Rep_time comment time

Connect to the database file conn. asp

The following is a code snippet:
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =" & Server. MapPath ("db \ windsn. mdb ")
%>

Then, add a line of code before each page to connect to the database: <! -- # Include file = "../Conn. asp" -->

Ii. Set the session

To prevent unauthorized logon, we need to create a session. asp.

The following is a code snippet:
<%
If session ("name") = "" then
'If the user name does not exist, login is restricted. (You can also set another field to increase security)
'If only you are the administrator, you can change the name above to if session ("name") <> "yourname" 'Then, which provides higher security and does not have to worry about vulnerabilities, but it is not flexible.
Response. write "<script> alert ('Sorry, you have not logged on! ');
Location = 'HTTP: // www.windsn.com/admin.asp' </script>"
Response. end
End if
%>

Then add a line of code in front of each page: <! -- # Include file = "session. asp" -->

3. Log On As an administrator

1. logon Interface

Log on to the admin. asp file. check. asp for verification.

The following is a code snippet:

<Table width = "755" border = "0" align = "center" cellspacing = "1" style = "font-size: 13px;">
<Form name = "form1" method = "POST" action = "check. asp">
<Tr align = "center" bgcolor = "# eeeeee">
<Td height = "35" colspan = "2" style = "font-size: 15px;"> <B> administrator portal </B> </td>
</Tr>
<Tr bgcolor = "# eeeeee">
<Td width = "308" align = "right"> <B> User name: </B> </td>
<Td width = "440"> <input name = "name" type = "text" class = "table" id = "name" size = "25"> </td>
</Tr>
<Tr bgcolor = "# eeeeee">
<Td align = "right"> <B> password: </B> </td>
<Td> <input name = "pwd" type = "password" class = "table" id = "pwd" size = "25"> </td>
</Tr>
<Tr bgcolor = "# eeeeee">
<Td colspan = "2"> </td>
</Tr>
<Tr align = "center" bgcolor = "# eeeeee">
<Td colspan = "2"> <input name = "Submit" type = "submit" class = "table" value = "">
<Input name = "Submit2" type = "button" class = "table" value = "Remove"
OnClick = "javascript: window. location. href = 'HTTP: // www.windsn.com/'"> </td>
</Tr>
</Form>
</Table>

Verify the logon page check. asp <% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>

The following is a code snippet:
<! -- # Include file = "../Conn. asp" -->
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> user verification </title>
</Head>
<%
Name = request. form ("name") 'Get the user name
Name = replace (name ,"'","")
Pwd = request. form ("pwd") 'get the password
Set rs = server. CreateObject ("adodb. recordset ")
Sqlstr = "select * from admin where name = '" & name & "'" & "and pwd = '" & pwd &"'"
Rs. open sqlstr, conn, 1, 1
If rs. eof then
Response. redirect "error. asp" 'logon failed to go to the error. asp page
Else
Session ("name") = request. form ("name ")
'Set the session value to restrict logon to the page. With this line of code, I will refer to the above mentioned <! -- # Include file = "session. asp "--> Add the code to the page that requires logon restriction. This page must be successfully logged on before accessing response. redirect "admins. asp "'log on to admins. asp management page, 'add to this page! -- # Include file = "session. asp" --> code
End if
%>
<Body>
</Body>
</Html>

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.