ASP个人网站与动网整合非官方方法
程序员文章站
2022-07-01 23:49:25
虽然动网已提供有详细的"动网论坛系统api接口开发人员指南",但像我这样的菜鸟一时半会可是参详不透的,汗。不甘心,在对其登录、验证等函数进行一番研究再加以测试后最终竟也小有...
虽然动网已提供有详细的"动网论坛系统api接口开发人员指南",但像我这样的菜鸟一时半会可是参详不透的,汗。不甘心,在对其登录、验证等函数进行一番研究再加以测试后最终竟也小有所成,菜鸟也有菜鸟的办法:
本次测试的论坛版本为version 7.1.0 sp1,未对其他版本做进行测试
一、网站文件结构
wwwroot
┝ index.asp
┝ checkuserlogin.asp
┕ bbs/
二、整合原理
对于同步更新实现不困难,整合主要问题就是难在同步登录,所以我们的重点都将放在讨论如何实现同步登录上。我的方法是将主站用户表整合至动网用户表dv_user中(免去以后得更新两个库的麻烦),可按需要在dv_user新增字段,并对bbs/login.asp和bbs/inc/dv_clsmain.asp做适当的修改;登录时将表单发至bbs/login.asp进行验证;主站根据动网登录成功后在session记录的信息判断是否登录成功,并取得用户资料。
三、新增修改文件
1.index.asp code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>个人网站与动网整合(www.mzwu.com)</title>
</head>
<body>
<!--#include file="checkuserlogin.asp" -->
<%
if checkuserlogin then
response.write("<a href=""bbs/logout.asp?back=1"">退出登陆</a><p></p>")
response.write("用户名:" & request.cookies("username") & "<br>")
response.write("性别:" & request.cookies("sex") & "<br>")
response.write("注册时间:" & request.cookies("joindate") & "<br>")
response.write("最后登录:" & request.cookies("lastlogin") & "<br>")
response.write("登录次数:" & request.cookies("userlogins") & "<br>")
response.write("浏览器类型:" & request.cookies("browser") & "<br>")
response.write("浏览器版本:" & request.cookies("version") & "<br>")
response.write("操作系统:" & request.cookies("platform") & "<br>")
else
%>
<form id="form1" name="form1" method="post" action="bbs/login.asp?action=chk&back=1">
用户名:
<input name="username" type="text" id="username" size="10" />
<br />
密 码:
<input name="password" type="password" id="password" size="10" />
<input type="submit" name="submit" value="登录" />
</form>
<%
end if
%>
<p></p><a href="bbs/">进入论坛</a>
</body>
</html>
2.checkuserlogin.asp code:
<!--#include file="bbs/inc/dv_clsmain.asp"-->
<%
function checkuserlogin()
dim dvbbs,usersession
const msxmlversion=".3.0"
set dvbbs = new cls_forum
set usersession=server.createobject("msxml2.freethreadeddomdocument"& msxmlversion)
if usersession.loadxml(session(dvbbs.cachename & "userid")&"") then
if usersession.documentelement.selectsinglenode("userinfo/@userid").text<>"0" then
'在论坛登录成功
checkuserlogin = true
'下边是用户一些信息的获取方法,可自行将其保存于cookies或session中便于使用:
'用户id : usersession.documentelement.selectsinglenode("userinfo/@userid").text
'用户名 : usersession.documentelement.selectsinglenode("userinfo/@username").text
'生日 : usersession.documentelement.selectsinglenode("userinfo/@userbirthday").text
'电子邮箱 : usersession.documentelement.selectsinglenode("userinfo/@useremail").text
'性别 : usersession.documentelement.selectsinglenode("userinfo/@usersex").text '0为女,1为男
'注册时间 : usersession.documentelement.selectsinglenode("userinfo/@joindate").text
'最后登录 : usersession.documentelement.selectsinglenode("userinfo/@lastlogin").text
'登录次数 : usersession.documentelement.selectsinglenode("userinfo/@userlogins").text
'金钱 : usersession.documentelement.selectsinglenode("userinfo/@userwealth").text
'积分 : usersession.documentelement.selectsinglenode("userinfo/@userep").text
'魅力 : usersession.documentelement.selectsinglenode("userinfo/@usercp").text
'最后登录ip : usersession.documentelement.selectsinglenode("userinfo/@userlastip").text
'浏览器类型 : usersession.documentelement.selectsinglenode("agent/@browser").text
'浏览器版本 : usersession.documentelement.selectsinglenode("agent/@version").text
'操作系统 : usersession.documentelement.selectsinglenode("agent/@platform").text
'来访ip : usersession.documentelement.selectsinglenode("agent/@ip").text
'举例应用:
response.cookies("username") = usersession.documentelement.selectsinglenode("userinfo/@username").text
response.cookies("joindate") = usersession.documentelement.selectsinglenode("userinfo/@joindate").text
if usersession.documentelement.selectsinglenode("userinfo/@usersex").text="0" then
response.cookies("sex") = "靓妹"
else
response.cookies("sex") = "酷哥"
end if
response.cookies("lastlogin") = usersession.documentelement.selectsinglenode("userinfo/@lastlogin").text
response.cookies("userlogins") = usersession.documentelement.selectsinglenode("userinfo/@userlogins").text
response.cookies("browser") = usersession.documentelement.selectsinglenode("agent/@browser").text
response.cookies("version") = usersession.documentelement.selectsinglenode("agent/@version").text
response.cookies("platform") = usersession.documentelement.selectsinglenode("agent/@platform").text
else
'访问过论坛尚未登录,为来宾状态
checkuserlogin = false
end if
else
'未访问过论坛
checkuserlogin = false
end if
set usersession = nothing
set dvbbs = nothing
end function
%>
3.bbs/login.asp新增红色部分,使在站点首页登录成功后仍能返回首页:
dim comeurlname
if instr(lcase(request("comeurl")),"reg.asp")>0 or instr(lcase(request("comeurl")),"login.asp")>0 or trim(request("comeurl"))="" then
comeurlname=""
comeurl="index.asp"
else
comeurl=request("comeurl")
comeurlname="<li><a href="&request("comeurl")&">"&request("comeurl")&"</a></li>"
end if
if request("back")="1" then
response.redirect("../index.asp")
end if
dim tempstr
tempstr = template.html(2)
'if dvbbs.forum_chansetting(0)=1 and dvbbs.forum_chansetting(10)=1 and dvbbs.forum_chansetting(12)=1 then
' tempstr = replace(tempstr,"{$ray_logininfo}",template.html(3))
'else
' tempstr = replace(tempstr,"{$ray_logininfo}","")
'end if
'-----------------------------------------------------------------
'系统整合
'-----------------------------------------------------------------
if dvapi_enable then
response.write dvapi_savecookie
response.flush
end if
'-----------------------------------------------------------------
tempstr = replace(tempstr,"{$ray_logininfo}","")
tempstr = replace(tempstr,"{$comeurl}",comeurl)
tempstr = replace(tempstr,"{$comeurlinfo}",comeurlname)
tempstr = replace(tempstr,"{$forumname}",dvbbs.forum_info(0))
response.write tempstr
tempstr=""
end function
4.bbs/logout.asp新增红色部分,使在站点首页点退出登录后仍能返回首页:
'-----------------------------------------------------------------
'系统整合
'-----------------------------------------------------------------
dim dvapi_obj,dvapi_savecookie,syskey
if dvapi_enable then
md5old = 1
syskey = md5(dvbbs.membername&dvapi_syskey,16)
md5old = 0
set dvapi_obj = new dvapi
dvapi_savecookie = dvapi_obj.setcookie(syskey,dvbbs.membername,"","")
set dvapi_obj = nothing
response.write dvapi_savecookie
response.flush
end if
if request("back")="1" then
response.redirect("../index.asp")
end if
'-----------------------------------------------------------------
'response.redirect dvbbs.forum_info(11)
response.write"<script language=javascript>"
response.write"settimeout(""window.location='"&dvbbs.forum_info(11)&"'"",1000);"
response.write"</script>"
四、动网设置:去掉登录验证码,ok,整合完毕。
五、扩展:
默认dv_user表中的字段有些时候并不能满足我们的实际需求,我们就需要新增字段对其进行扩展,动手吧:
1.打开dv_user表新增一文本类型字段info_1
2.bbs/login.asp的chkuserlogin函数中
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin,lastlogin as cometime , lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid"
修改为:
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin,lastlogin as cometime , lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid,info_1"
3.bbs/inc/dv_clsmain.asp的truecheckuserlogin函数中
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin as cometime ,lastlogin,lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid"
修改为:
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin as cometime ,lastlogin,lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid,info_1"
4.checkuserlogin.asp中
response.cookies("platform") = usersession.documentelement.selectsinglenode("agent/@platform").text
后添加
response.cookies("info_1") = usersession.documentelement.selectsinglenode("userinfo/@info_1").text
5.index.asp中
response.write("操作系统:" & request.cookies("platform") & "<br>")
后添加
response.write("新增:" & request.cookies("info_1") & "<br>")
6.ok,圆满完成
本次测试的论坛版本为version 7.1.0 sp1,未对其他版本做进行测试
一、网站文件结构
wwwroot
┝ index.asp
┝ checkuserlogin.asp
┕ bbs/
二、整合原理
对于同步更新实现不困难,整合主要问题就是难在同步登录,所以我们的重点都将放在讨论如何实现同步登录上。我的方法是将主站用户表整合至动网用户表dv_user中(免去以后得更新两个库的麻烦),可按需要在dv_user新增字段,并对bbs/login.asp和bbs/inc/dv_clsmain.asp做适当的修改;登录时将表单发至bbs/login.asp进行验证;主站根据动网登录成功后在session记录的信息判断是否登录成功,并取得用户资料。
三、新增修改文件
1.index.asp code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>个人网站与动网整合(www.mzwu.com)</title>
</head>
<body>
<!--#include file="checkuserlogin.asp" -->
<%
if checkuserlogin then
response.write("<a href=""bbs/logout.asp?back=1"">退出登陆</a><p></p>")
response.write("用户名:" & request.cookies("username") & "<br>")
response.write("性别:" & request.cookies("sex") & "<br>")
response.write("注册时间:" & request.cookies("joindate") & "<br>")
response.write("最后登录:" & request.cookies("lastlogin") & "<br>")
response.write("登录次数:" & request.cookies("userlogins") & "<br>")
response.write("浏览器类型:" & request.cookies("browser") & "<br>")
response.write("浏览器版本:" & request.cookies("version") & "<br>")
response.write("操作系统:" & request.cookies("platform") & "<br>")
else
%>
<form id="form1" name="form1" method="post" action="bbs/login.asp?action=chk&back=1">
用户名:
<input name="username" type="text" id="username" size="10" />
<br />
密 码:
<input name="password" type="password" id="password" size="10" />
<input type="submit" name="submit" value="登录" />
</form>
<%
end if
%>
<p></p><a href="bbs/">进入论坛</a>
</body>
</html>
2.checkuserlogin.asp code:
<!--#include file="bbs/inc/dv_clsmain.asp"-->
<%
function checkuserlogin()
dim dvbbs,usersession
const msxmlversion=".3.0"
set dvbbs = new cls_forum
set usersession=server.createobject("msxml2.freethreadeddomdocument"& msxmlversion)
if usersession.loadxml(session(dvbbs.cachename & "userid")&"") then
if usersession.documentelement.selectsinglenode("userinfo/@userid").text<>"0" then
'在论坛登录成功
checkuserlogin = true
'下边是用户一些信息的获取方法,可自行将其保存于cookies或session中便于使用:
'用户id : usersession.documentelement.selectsinglenode("userinfo/@userid").text
'用户名 : usersession.documentelement.selectsinglenode("userinfo/@username").text
'生日 : usersession.documentelement.selectsinglenode("userinfo/@userbirthday").text
'电子邮箱 : usersession.documentelement.selectsinglenode("userinfo/@useremail").text
'性别 : usersession.documentelement.selectsinglenode("userinfo/@usersex").text '0为女,1为男
'注册时间 : usersession.documentelement.selectsinglenode("userinfo/@joindate").text
'最后登录 : usersession.documentelement.selectsinglenode("userinfo/@lastlogin").text
'登录次数 : usersession.documentelement.selectsinglenode("userinfo/@userlogins").text
'金钱 : usersession.documentelement.selectsinglenode("userinfo/@userwealth").text
'积分 : usersession.documentelement.selectsinglenode("userinfo/@userep").text
'魅力 : usersession.documentelement.selectsinglenode("userinfo/@usercp").text
'最后登录ip : usersession.documentelement.selectsinglenode("userinfo/@userlastip").text
'浏览器类型 : usersession.documentelement.selectsinglenode("agent/@browser").text
'浏览器版本 : usersession.documentelement.selectsinglenode("agent/@version").text
'操作系统 : usersession.documentelement.selectsinglenode("agent/@platform").text
'来访ip : usersession.documentelement.selectsinglenode("agent/@ip").text
'举例应用:
response.cookies("username") = usersession.documentelement.selectsinglenode("userinfo/@username").text
response.cookies("joindate") = usersession.documentelement.selectsinglenode("userinfo/@joindate").text
if usersession.documentelement.selectsinglenode("userinfo/@usersex").text="0" then
response.cookies("sex") = "靓妹"
else
response.cookies("sex") = "酷哥"
end if
response.cookies("lastlogin") = usersession.documentelement.selectsinglenode("userinfo/@lastlogin").text
response.cookies("userlogins") = usersession.documentelement.selectsinglenode("userinfo/@userlogins").text
response.cookies("browser") = usersession.documentelement.selectsinglenode("agent/@browser").text
response.cookies("version") = usersession.documentelement.selectsinglenode("agent/@version").text
response.cookies("platform") = usersession.documentelement.selectsinglenode("agent/@platform").text
else
'访问过论坛尚未登录,为来宾状态
checkuserlogin = false
end if
else
'未访问过论坛
checkuserlogin = false
end if
set usersession = nothing
set dvbbs = nothing
end function
%>
3.bbs/login.asp新增红色部分,使在站点首页登录成功后仍能返回首页:
dim comeurlname
if instr(lcase(request("comeurl")),"reg.asp")>0 or instr(lcase(request("comeurl")),"login.asp")>0 or trim(request("comeurl"))="" then
comeurlname=""
comeurl="index.asp"
else
comeurl=request("comeurl")
comeurlname="<li><a href="&request("comeurl")&">"&request("comeurl")&"</a></li>"
end if
if request("back")="1" then
response.redirect("../index.asp")
end if
dim tempstr
tempstr = template.html(2)
'if dvbbs.forum_chansetting(0)=1 and dvbbs.forum_chansetting(10)=1 and dvbbs.forum_chansetting(12)=1 then
' tempstr = replace(tempstr,"{$ray_logininfo}",template.html(3))
'else
' tempstr = replace(tempstr,"{$ray_logininfo}","")
'end if
'-----------------------------------------------------------------
'系统整合
'-----------------------------------------------------------------
if dvapi_enable then
response.write dvapi_savecookie
response.flush
end if
'-----------------------------------------------------------------
tempstr = replace(tempstr,"{$ray_logininfo}","")
tempstr = replace(tempstr,"{$comeurl}",comeurl)
tempstr = replace(tempstr,"{$comeurlinfo}",comeurlname)
tempstr = replace(tempstr,"{$forumname}",dvbbs.forum_info(0))
response.write tempstr
tempstr=""
end function
4.bbs/logout.asp新增红色部分,使在站点首页点退出登录后仍能返回首页:
'-----------------------------------------------------------------
'系统整合
'-----------------------------------------------------------------
dim dvapi_obj,dvapi_savecookie,syskey
if dvapi_enable then
md5old = 1
syskey = md5(dvbbs.membername&dvapi_syskey,16)
md5old = 0
set dvapi_obj = new dvapi
dvapi_savecookie = dvapi_obj.setcookie(syskey,dvbbs.membername,"","")
set dvapi_obj = nothing
response.write dvapi_savecookie
response.flush
end if
if request("back")="1" then
response.redirect("../index.asp")
end if
'-----------------------------------------------------------------
'response.redirect dvbbs.forum_info(11)
response.write"<script language=javascript>"
response.write"settimeout(""window.location='"&dvbbs.forum_info(11)&"'"",1000);"
response.write"</script>"
四、动网设置:去掉登录验证码,ok,整合完毕。
五、扩展:
默认dv_user表中的字段有些时候并不能满足我们的实际需求,我们就需要新增字段对其进行扩展,动手吧:
1.打开dv_user表新增一文本类型字段info_1
2.bbs/login.asp的chkuserlogin函数中
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin,lastlogin as cometime , lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid"
修改为:
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin,lastlogin as cometime , lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid,info_1"
3.bbs/inc/dv_clsmain.asp的truecheckuserlogin函数中
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin as cometime ,lastlogin,lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid"
修改为:
sql="select userid,username,userpassword,useremail,userpost,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin as cometime ,lastlogin,lastlogin as activetime,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid,info_1"
4.checkuserlogin.asp中
response.cookies("platform") = usersession.documentelement.selectsinglenode("agent/@platform").text
后添加
response.cookies("info_1") = usersession.documentelement.selectsinglenode("userinfo/@info_1").text
5.index.asp中
response.write("操作系统:" & request.cookies("platform") & "<br>")
后添加
response.write("新增:" & request.cookies("info_1") & "<br>")
6.ok,圆满完成