以前用ASP写的留言本

前些日子整理的代码

 


<%@ LANGUAGE = VBScript CodePage = 936%>
<%
'程序出处  :VA GuestBook System By Vanery
'版 本     :Version 1.16单用户精简版  (新版本研究中)
'QQ        :296338925
'Email     :[email protected]
'声 明     :本程序仅供ASP编程爱好者参考学习,所有代码均开源提供。
'发布日期  :2007年9月19日
'作 者     :阿威
'官网地址  :jaker.137.tofor.com
'初始帐号  :admin 密码:123465
'
'-----------------------------------------------------------------------------------连接数据库
Dim Conn,Connstr,uip,SiteName,wtime,StartTime
StartTime = Timer()
SiteName="VA GuestBook System"                                  '-------------------留言本名字
wtime=now()
 Set Conn=Server.CreateObject("ADODB.Connection")
 DB="Images/#data.mdb"
 Connstr="DBQ="+server.mappath(DB)+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}"
 on error resume next
 Conn.open Connstr
If Err Then
 err.Clear
 Set Conn = Nothing
 Response.Write "数据库连接出错,请检查连接字串。"
 Response.End
End If
'--------------------------------------------------------------------------------------获取IP
uip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
 If uip = "" Then uip = Request.ServerVariables("REMOTE_ADDR")
'-----------------------------------------------------------------------------------定义文字内容规范 
 Function MyReplace(sMsg)
  sMsg = Trim(sMsg)
  sMsg = Replace(sMsg, "<", "<")
  sMsg = Replace(sMsg, ">", ">")
  sMsg = Replace(sMsg, Chr(13) & Chr(10), "
")          '回车换行
  sMsg = Replace(sMsg, Chr(32), "  ")          '空格
  sMsg = Replace(sMsg, Chr(34), """)                  ' " 双引号
  sMsg = Replace(sMsg, Chr(9), "    ") 'Tab
  MyReplace = sMsg
 End Function
'------------------------------------------------------------------------------------------
%>


/>
/>
<%=SiteName%>





 
   
 
 
   
 
 
   
 <%=SiteName%>      首 页|<%If Session("admin")="" then%>管理员登陆<%Else%>  注销登陆|修改密码|当前操作员:<%=Session("admin")%><%End If%>

 

 

<%
Dim Action,Admin
Set Rs = Server.CreateObject("ADODB.Recordset")
Action = Request.QueryString("Action")
Admin = "$Admin001"
Select Case Action
    Case "Add"        '-------------------------------------------------添加留言
   title=MyReplace(request.Form("title"))
   if session("admin")="" Then
    nam=Replace(request.Form("nam"),Chr(32),"")
    if nam="管理员" then nam="猪头三"
    if nam="admin" then nam="猪头三"
    nam=MyReplace(request.Form("nam"))
    
   else  
   nam="admin"
   msg = Replace(request.Form("msg"), Chr(13) & Chr(10), "
")
   end if
   msg=MyReplace(request.Form("msg"))
   sex=request.Form("sex")
   email=MyReplace(request.Form("email"))
   conn.execute "insert into Content (Title,Wname,Wsex,Msg,Wtime,WIP) values ('"&title&"','"&nam&"','"&sex&"','"&msg&"','"&Wtime&"','"&uip&"')"
   set title=nothing
   set nam=nothing
   set sex=nothing
   set msg=nothing
   set email=nothing
   response.write ""
   response.redirect "GuestBook.asp"
    Case "Delete"     '-----------------------------------------------删除留言
      if request("id")<>empty then
    if session("admin")="" then
     response.redirect ("login.asp")
    end if
   conn.Execute("delete * from Content where gid="&trim(request("id")))
   end if
   response.redirect "GuestBook.asp"
    Case "Seta"    '-----------------------------------------------置顶留言
      if request("id")<>"" then
    if session("admin")="" then
     response.redirect ("login.asp")
    end if
   conn.Execute("update Content set Sets=1 where gid="&trim(request("id")))
   end if
   response.redirect "GuestBook.asp"
  Case "Setat"    '-----------------------------------------------解除置顶留言
      if request("id")<>"" then
    if session("admin")="" then
     response.redirect ("login.asp")
    end if
   conn.Execute("update Content set Sets=0 where gid="&trim(request("id")))
   end if
   response.redirect "GuestBook.asp"
      Case "Revert"     '------------------------------------------------显示回复表单
      if session("admin")="" then
     response.redirect ("login.asp")
   end if
    Sql = "Select * From Content Where GID="&trim(request("id"))
    rs.open sql,conn,1,1
    %>
   
" name="huifu" method="post">
   
回复<%=rs("wname")%>的留言

   

   

 <%
      set sql=nothing
   set Rs=nothing
   response.Write("
")
    Case "EditRevert" '------------------------------------------------编辑留言
  if session("admin")="" then
   response.redirect ("login.asp")
   end if
    Sql = "Select * From Content Where GID="&trim(request("id"))
    rs.open sql,conn,1,1
    %>
   
" name="huifu" method="post">
   
编辑 管理员 <%=Rs("Wtime")%> 发布的留言信息

   

   

<%
    Case "SaveEdit" '------------------------------------------------保存编辑
         if request("id")<>empty then
    if session("admin")="" then
     response.redirect ("login.asp")
    end if
   conn.Execute("update Content set msg='"&(request.Form("gmhuifu"))&"' where gid="&trim(request("id")))
   end if
   response.redirect "GuestBook.asp"
    Case "SaveRevert" '------------------------------------------------保存回复
         if request("id")<>empty then
    if session("admin")="" then
     response.redirect ("login.asp")
    end if
   conn.Execute("update Content set RConten='"&MyReplace(request.Form("gmhuifu"))&"' where gid="&trim(request("id")))
   end if
   response.redirect "GuestBook.asp"
    Case "Login"      '------------------------------------------------登进
     If Session("Admin")="" then
   If Request.ServerVariables("Request_Method")="GET" then
   response.write("

")
   response.write(" ")
   response.write("")
   response.write("")
   response.write("")
   response.write("")
   response.write("
用户名:
管理密码:
")
   response.write("
")
   response.Write("")
   else   
   Dim Username,Password
   Username=request.form("UserName")
   Password=request.form("Password")
   sql="SELECT * FROM admin where username='"&Username&"' and upassword='"&Password&"'"
   rs.open sql,conn,1,1
    if rs.eof or rs.bof then
   response.write ""
   response.end
    else
  session("admin")=Username
  set sql=nothing
  set Password=nothing
  set Username=nothing
  response.redirect "?"
    end if
   end if
  Else
  response.Write("已登陆用户! 秒后返回")
  End if
    Case "LoginOut"   '-----------------------------------------------------------登出
      Session("Admin") = ""
   Response.Redirect("?")
    Case "rePassword" '-----------------------------------------------------------修改密码
      If Session("Admin")<>Empty then
    response.Write("
新密码: ")
    response.Write("    
")
    response.Write("")
   Else
    Response.Redirect("GuestBook.asp")
   
   End If
    Case "SavePassword"  '----------------------------------------------------------保存修改密码
      If Session("Admin")="" then
    Response.Redirect("GuestBook.asp")
    response.End()
   End If
    saPassword=MyReplace(request.Form("rePassword"))
    conn.Execute("update Admin set upassword='"&saPassword&"' where UID=1")
    response.Write ("")
    Case Else          '----------------------------------------------------------正式显示

    Sql = "Select * From Content Order BY Sets desc , Gid Desc"
  Rs.Open Sql,conn,1,1
  IF Rs.Eof or rs.bof Then
        Response.Write "

目前还没有任何信息"
    else
   totalrecord=rs.recordcount
   IF Request("s")="" Then
    ShowNum=10
   Else
    ShowNum=Request("s")
   End IF
  rs.pagesize=ShowNum
  maxpage=rs.pagecount
  requestpage=clng(request("p"))
   if requestpage="" or requestpage=0 then
      requestpage=1
   end if
  if resquestpage>maxpage then
      resquestpage=maxpage
  end if

  if not requestpage=1 then
  rs.move (requestpage-1)*rs.pagesize
  end if
for i=1 to rs.pagesize and not rs.bof
%>
       


         
           
           
         
       

<% If Rs("wname")="admin" then %>管理员<%else%><%=Rs("wname")%><%end if%>


                .jpg" border="0">

               
                 
               
               
                 
               
           

                     
                       
      
                       
                     
                 

       
      <%If Rs("Sets")=1 then
      response.Write("『置顶』 ")
      End If%><%=Rs("title")%>

      <%if session("admin")<>"" then
           If Rs("Sets")=1 then
      %>
       " title=解除置顶>解顶
      <%else%>
       " title=置顶此条信息>置顶<%end if%>
      <%if Rs("Wname")="admin" then
      %>
       " title=编辑此条信息>编辑
      <%end if%>
       " title=回复此条信息>回复
       " title=删除此条信息>删除
      <%end if%>
<%=trim(rs("wtime"))%> 

                     
                       
                     
                   
<%=rs("msg")%>

                     

     

        <% Rs.MoveNext
if rs.eof then exit for
next
End If
set sql=nothing
%>
 
     共 <%=maxpage%> 页  分页: [
      <%
For i=1 to maxpage
Response.Write ""&i&" "
Next
%>
      ]
 

<%
response.Write("
")
response.Write(" ")
response.Write("")
response.Write("")
response.Write("
标 题:
姓 名:
性 别: 男 
内 容:
  
")
End Select
Set Conn=Nothing
Set Connstr=Nothing
Set uip=Nothing
Set SiteName=Nothing
Set wtime=Nothing
Response.Write (" ")
Response.Write ("")
Response.Write ("
")
Set StartTime=Nothing
response.End()
%>
 

你可能感兴趣的:(asp,session,border,action,javascript,sql)