服务器 频道

简单ASP留言本程序及部分代码讲解

  【IT168 服务器学院】简单ASP留言本程序及部分代码讲解,适合新手!!

  文件分解

总共文件包含:config.asp,gbdata.mdb,help.asp,index.asp,style.css,UBB.ASP,images
config.asp          留言本配置文件
gbdata.mdb        留言本数据库文件
help.asp            留言本帮助文档
index.asp          留言本主要文件
style.css           留言本样式表文件
UBB.ASP          留言本UBB代码转换文件
images            留言本图片文件

config.asp

 

  CODE:  
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Option Explicit
Dim gbname,mpass,mskin,action,skinnum,i
Dim tmpname,tmptopic,id,lid,tmpinfo,tmpDefault
Dim conn,connstr,rs,sql,Datepath
Dim topic,user,wtime,word,oicq,email,islook
Dim password

''*******设置以下部分即可****************************

gbname="Freeing''s Gbook!"        ''留言本的名称
mpass="im286.com"                        ''管理员密码
mskin=1                                ''默认模板(1-7)
Datepath="gbdata.mdb"                ''数据库名称的路径
''首页默认显示内容
tmpDefault="<p style=''margin:5px;''><img src=''images/list.gif''>&nbsp;关于本子:</p>"&_
                "<p style=''margin:3px;margin-left:15px;font:12px;''>"&_
                "无版权,可以任意修改。"&_
                "<br>无技术含量,简单的一个留言功能。"&_
                "<br>模板比较好看,如果你喜欢可以自己添加些功能。"&_
                "<br>我现在失业中。。。能否给偶谋份工作?"&_
                "<br>如果你需要这个本子更大的功能,请联系作者给你顶做(要米米的^_^)。"&_
                "<br><br>默认管理员密码是:im286.com"&_
                "<br><br><p style=''margin:5px;''><img src=''images/list.gif''>&nbsp;相关连接:</p>"&_
                "<p style=''margin:3px;margin-left:15px;font:12px;''>"&_
                "<a href=''help.asp?ubb''>UBB帮助</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=''help.asp?read''>说明文件</a>&nbsp;&nbsp;&nbsp;&nbsp;"&_
                ""&_
                "<br><a href=''http://www.im286.com/'' target=''_blank''>落伍者论坛</a>&nbsp;&nbsp;&nbsp;&nbsp;<font color=''c3c3c3''>我还没页子^_^''(没得空间&_&)</font>"&_
                "&nbsp;&nbsp;&nbsp;&nbsp;<a href=''http://www.xn180.com/''>咸宁桂乡</a>"&_
                ""

''************************************************
tmpname=""          ''默认当前摸块名称变量
tmptopic=""           ''首页临时显示主题变量
id=trim(request.querystring("id"))          ''获取当前查看留言的ID
skinnum=trim(request.querystring("skin"))          ''获取当前用户选择的摸板值
action=LCase(trim(request.querystring("action")))          ''获取当前摸块

On Error Resume Next          ''容错
Set conn = Server.CreateObject("ADODB.Connection")          ''创建ADODB连接
''connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(Datepath)
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(Datepath)          ''数据库驱动
conn.Open connstr          ''打开数据库

If Err Then          ''如果有错误
        Err.Clear          ''清除错误
        Set Conn = Nothing          ''关闭数据库连接
        Response.Write "数据库连接出错,请检查连接字串。"          ''输出错误信息
        Response.End          ''结束输出
End If

Function post_chk()          ''判断数据来源函数,返回"yes"
        Dim server_v1,server_v2
        post_chk="no"
        server_v1=Request.ServerVariables("HTTP_REFERER")
        server_v2=Request.ServerVariables("SERVER_NAME")
        If mid(server_v1,8,len(server_v2))=server_v2 then post_chk="yes":Exit Function
End Function
%>

gbdata.mdb

表:Im286_freeing_gbdata
ID,自动编号          ''留言的唯一识别号,是唯一的
topic,文本,字段大小50          ''留言的标题
user,文本,字段大小50          ''留言者
oicq,数字,长整(PS:整数就可以了^_^)          ''留言者的OICQ号码
email,文本,字段大小50          ''留言这的EMAIL
islook,是否          ''是否是隐藏的,隐藏的仅管理员登录后可见
word,备注          ''留言的内容
rword,备注          ''回复的内容
wtime,时间/日期          ''留言时间
rtime,时间/日期          ''管理员回复时间

help.asp

<!--#include file=config.asp-->          ''包含 config.asp 文件
<%
''输出样式表和表格
Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""style.css""><table width=''100%''><tr>"
Dim Reques          ''定义变良名
Reques=Trim(Request.querystring())          ''给变量赋值
if Reques="ubb" then          ''如果返回的值是"ubb",返回关于UBB的帮助,以下类同
        Response.Write "<td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> EM 图标列表</td></tr><tr>"
        For i = 1 to 16
                Response.Write "<td bgcolor=''#f7f7f7''><img src=''images/ubb/em/em"&i&".gif'' border=''0'' align=''absMiddle''> EM"&i&"</td>"
        If i mod 8=0 then Response.Write "</tr><tr>"
        Next
        Response.Write "<tr><td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> EMB 图标列表</td></tr><tr>"
        For i = 1 to 28
                Response.Write "<td bgcolor=''#f7f7f7''><img src=''images/ubb/em/emb"&i&".gif'' border=''0'' align=''absMiddle''> EMB"&i&"</td>"
        If i mod 8=0 then Response.Write "</tr><tr>"
        Next
        Response.Write "<tr><td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> 其他说明</td></tr><tr>"
        Response.Write "<tr><td  bgcolor=''#f7f7f7'' colspan=8>支持常用UBB代码,如:[IMG],[URL],[MAIL].....</td></tr><tr>"
elseif Reques="about" then
        Response.Write "<td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> 关于留言本</td></tr><tr>"
        Response.Write "<td bgcolor=''#f7f7f7'' colspan=8><p><img src=''images/llist.gif'' align=''absmiddle''> "&_
                "前面已经说了,这里不用重复了。"&_
                "</td>"

elseif Reques="last" then

Set Rs=Server.CreateObject("ADODB.RECORDSET")
sql="select top 100 id,topic,islook from Im286_freeing_gbdata order by wtime desc"
rs.open sql,conn,1,1

i=0
If rs.eof then
        tmptopic="<img src=''./images/llist.gif'' border=''0'' align=''absMiddle''> 还没有留言呢!"
Else
Do while Not Rs.EOF
i=i+1
                If rs.eof or rs.bof then exit Do
                if rs("islook")=true then
                Tmptopic=tmptopic&"<img src=''./images/llist.gif'' align=''adsMiddle''> " & i & " <a href=''?skin="&skinnum&"&action=read&id="&rs("id")&"'' title=''隐藏''><font color=#808080>"&rs("topic")&"...</font></a><br>"
                else
                Tmptopic=tmptopic&"<img src=''./images/llist.gif'' align=''adsMiddle''> " & i & " <a href=''?skin="&skinnum&"&action=read&id="&rs("id")&"'' title=''公开''>"&rs("topic")&"...</a><br>"
                end if
                Rs.MoveNext       
Loop
end if
rs.close
Set rs=Nothing
        Response.Write "<td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> 最后50条更新</td></tr>"&_
                        "<tr><td bgcolor=''#f7f7f7'' colspan=8><p>" & Tmptopic & _
                        "</td>"

elseif Reques="read" then
        Response.Write "<td bgcolor=''#ededed'' colspan=8><p><img src=''images/list.gif'' align=''absmiddle''> 帮助文档</td></tr><tr>"
        Response.Write "<td bgcolor=''#f7f7f7'' colspan=8><p><img src=''images/llist.gif'' align=''absmiddle''> "&_
                "没有写,这么垃圾的一个程序,没有必要写。"&_
                "</td>"
end if
Response.Write "</tr></table>"
%>

0
相关文章