程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> 後台管理登錄篇-asp設計與數據庫

後台管理登錄篇-asp設計與數據庫

編輯:關於ASP編程

實現功能不難,想要完善,甚至完美,那才叫難。
所以,小弟將功能實現帖出來,和各位初學者討論討論。至於完善,就看各位自己的想法了

一、建立數據庫

在就開始了,我建了一個名為windsn.mdb的數據庫,包含4張表
admin表(用於管理員信息):id, name(用戶名), pwd(密碼), ...
concent表(用於存放文檔數據):con_id, title, author, part, con, time, num
con_id 自動編號
title 文章標題
author 作者或出處
part 文章分類
con 文章內容
time 發表時間(用=now()做初始值)
num 被閱次數
part表(用於存放文檔分類數據):id, part(分類), num
reply表(用於文檔評論):con_id, rep_id, rep_name, rep_con, rep_time
con_id 與表concent中con_id字段相對應的字段,數字類型
rep_id 自動編號
rep_name 參與評論的用戶名
rep_con 評論的內容
rep_time 評論時間

連接數據庫文件conn.asp
以下是代碼片段:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db\windsn.mdb")
%>


然後,再每一個要連接數據庫的頁面前加入一行代碼:<!--#include file="../Conn.asp" -->

二、設置session

為了防止非法登錄,我們要建立一個session.asp。

以下是代碼片段:
<%
if session("name")="" then 
' 如果用戶名不存在,限制登錄。(還可以再設置一個字段以增加安全性)
' 如果管理員就只你一個人,那麼上面這名可改為if session("name")<>"yourname" 'then這樣安全性會更高,也不用怕有漏洞,但就不靈活了。
response.write"<script>alert('對不起,您還沒有登錄!');
location='http://www.windsn.com/admin.asp'</script>"
response.end
end if
%>


到時候在每個頁面前加入一行代碼:<!--#include file="session.asp" -->


三、管理員登錄

1,登錄界面


登錄界面admin.asp文件,我這裡設置到check.asp驗證

以下是代碼片段:

  <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>管理員入口</b></td>
      </tr>
    <tr bgcolor="#eeeeee">
      <td width="308" align="right"><b>用戶名:</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>密 碼:</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=" 取 消 " 
onClick="javascript:window.location.href='http://www.windsn.com/'"></td>
      </tr>
</form>
  </table>


驗證登錄頁check.asp<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
以下是代碼片段:
<!--#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>用戶驗證</title>
</head>
<%
name = request.form("name") '取得用戶名
name = replace(name,"'","") 
pwd = request.form("pwd")    '取得密碼
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" '登錄失敗進入error.asp頁
else
session("name")=request.form("name") 
' 設置session值,以便對頁面進行限制登錄。有了這行代碼,再將上面提到的<!--#include file="session.asp" -->代碼加入到需要限制登錄的頁面中,該頁面就必須登錄成功後才能訪問response.redirect "admins.asp" '登錄成功後進入admins.asp的管理頁,'本頁中就要加入<!--#include file="session.asp" -->代碼
end if
%>
<body>
</body>
</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved