管理页admin.asp其实跟留言板首页index.asp功能差不多,所以可以直接把index.asp另存为admin.asp,然后加上管理功能:删除,编辑,回复,显IP:

对于"删除"、"编辑"和"回复"的数据绑定很简单,主要是在链接的参数中传递当前留言的ID号,参考"QQ"的绑定方式,完成后的链接地址分别为: "删除":delete.asp?id=<%=(rs.Fields.Item("ID").Value)%> "编辑":edit.asp?id=<%=(rs.Fields.Item("ID").Value)%> "回复":reply.asp?id=<%=(rs.Fields.Item("ID").Value)%> 需要注意的是,由于admin.asp页是由index.asp页另存来的,而index.asp页所建的记录集里没有选择到"ID"字段,所以在这里必须把"ID"字段选进来,方法: 1)在服务器行为面板中双击"Recordset(rs)",重新选择字段 2)也可以直接在源码中找到 rs.Source = "SELECT Content, Date, Email, Homepage, ICON, IP, Name, QQ, RDate, Reply FROM main ORDER BY Date DESC" 这行,改为 rs.Source = "SELECT ID, Content, Date, Email, Homepage, ICON, IP, Name, QQ, RDate, Reply FROM main ORDER BY Date DESC"
对于IP的相关绑定,完成后代码为: 来自:<%=ip(rs.Fields.Item("IP").Value)%>[IP:<%=(rs.Fields.Item("IP").Value)%>]
这里用到一个叫ip的Function过程来查询访客IP在数据库表address中对应的国家和城市,代码如下:
<% Function ip(sip) Dim iparr,iprs,country,city 'IP为127.0.0.1时相当于192.168.0.1 If sip="127.0.0.1" then sip= "192.168.0.1" ‘以点"."为界切割字符串sip,如果sip为“192.168.0.1”,则切割后得到的数组iparr(0)="192",iparr(1)="168",iparr(2)="0",iparr(3)="1" iparr=split(sip,".") '通过计算转换,使IP地址跟数据库中的数据联系起来 sip=cint(iparr(0))*256*256*256+cint(iparr(1))*256*256+cint(iparr(2))*256+cint(iparr(3))-1
'连接数据库,查询数据库字段ip1和ip2满足关系ip1<=sip<=ip2的记录 Set iprs = Server.CreateObject("ADODB.Recordset") iprs.ActiveConnection = MM_conn_STRING iprs.Source = "SELECT Top 1 city, country FROM address WHERE ip1 <=" & sip & " and " & sip & "<=ip2" iprs.CursorType = 0 iprs.CursorLocation = 2 iprs.LockType = 1 iprs.Open()
'判断数据库中有无记录即无相应IP地址的信息时的处理 If iprs.bof and iprs.eof then country="未知地区" city="" Else country=iprs.Fields.Item("country").Value city=iprs.Fields.Item("city").Value End If ip=country&city
iprs.Close() Set iprs = Nothing End Function %>
参考DW自动生成的代码,把这段代码加到HTML代码开始之前
出处:闪吧
责任编辑:蓝色
上一页 添加留言页 [8] 下一页 登陆页 login.asp [10]
◎进入论坛网页制作、网站综合版块参加讨论
|