ASP类型个人网站与动网整合非官方方法(转帖)

2012/10/21 5:10:00  人气 970    计算机网络论坛  
个人网站如有会员注册模块+动网论坛的话,那网站要与动网论坛系统整合,实现不同web系统之间的用户信息同步更新、登录等操作就不是件容易的事了,虽然动网已提供有详细的“动网论坛系统api接口开发人员指南“,但像我这样的菜鸟一时半会可是参详不透的,汗。不甘心,在对其登录、验证等函数进行一番研究再加以测试后最终竟也小有所成,菜鸟也有菜鸟的办法,哈哈。
一、网站文件结构
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(“用户名:“ &amp; request.cookies(“username“) &amp; “<br>“)
response.write(“性别:“ &amp; request.cookies(“sex“) &amp; “<br>“)
response.write(“注册时间:“ &amp; request.cookies(“joindate“) &amp; “<br>“)
response.write
:“&amp; request.cookies(“lastlogin“) &amp; “<br>“)
response.write(“登录次数:“ &amp; request.cookies(“userlogins“) &amp; “<br>“)
response.write(“浏览器类型:“ &amp; request.cookies(“browser“) &amp; “<br>“)
response.write(“浏览器版本:“ &amp; request.cookies(“version“) &amp; “<br>“)
response.write(“操作系统:“ &amp; request.cookies(“platform“) &amp; “<br>“)
else
%>
<form id=“form1“ name=“form1“ method=“post“ action=“bbs/login.asp?action=chk&amp;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.*object(“msxml2.freethreadeddomd
br] ‘积分 : usersession.documentelement.*singlenode(“user*/@userep“).text
‘魅力 : usersession.documentelement.*singlenode(“user*/@usercp“).text
‘最后登录ip : usersession.documentelement.*singlenode(“user*/@userlastip“).text
‘浏览器类型 : usersession.documentelement.*singlenode(“agent/@browser“).text
‘浏览器版本 : usersession.documentelement.*singlenode(“agent/@version“).text
‘操作系统 : usersession.documentelement.*singlenode(“agent/@platform“).text
‘来访ip : usersession.documentelement.*singlenode(“agent/@ip“).text
‘举例应用:
response.cookies(“username“) = usersession.documentelement.*singlenode(“user*/@username“).text
response.cookies(“joindate“) = usersession.documentelement.*singlenode(“user*/@joindate“).text
if usersession.documentelement.*singlenode(“user*/@usersex“).text=“0“ then
response.cookies(“sex“) = “靓妹“
else
response.cookies(“sex“) = “酷哥“
end if
response.cookies(“lastlogin“) = usersession.documentelement.*s
inglenode(“user*/@lastlogin“).text
response.cookies(“userlogins“) = usersession.documentelement.*singlenode(“user*/@userlogins“).text
response.cookies(“browser“) = usersession.documentelement.*singlenode(“agent/@browser“).text
response.cookies(“version“) = usersession.documentelement.*singlenode(“agent/@version“).text
response.cookies(“platform“) = usersession.documentelement.*singlenode(“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=“&amp;request(“comeurl“)&amp;“>“&amp;request(“comeurl“)&amp;“</a&gt
;</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_login*}“,template.html(3))
‘else
‘ tempstr = replace(tempstr,“{$$$$$$$$ray_login*}“,““)
‘end if
‘-----------------------------------------------------------------
‘系统整合
‘-----------------------------------------------------------------
if dvapi_enable then
response.write dvapi_savecookie
response.flush
end if
‘-----------------------------------------------------------------
tempstr = replace(tempstr,“{$$$$$$$$ray_login*}“,““)
tempstr = replace(tempstr,“{$$$$$$$$comeurl}“,comeurl)
tempstr = replace(tempstr,“{$$$$$$$$comeurl*}“,comeurlname)
tempstr = replace(tempstr,“{$$$$$$$$forumname}“,dvbbs.forum_*(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&amp;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_*(11)
response.write“<script language=javascript>“
response.write“settimeout(““window.location=‘“&amp;dvbbs.forum_*(11)&amp;“‘““,1000);“
response.write“</script>“
四、动网设置:去掉登录验证码,ok,整合完毕。
五、扩展:
默认dv_user表中的字段有些时候并不能满足我们的实际需求,我们就需要新增字段对其进行扩展,动手吧:
1.打开dv_user表新增一文本类型字段*_1
2.bbs/login.asp的chkuserlogin函数中
sql=“* userid,username,userpassword,useremail,u
serpost,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=“* 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,*_1“
3.bbs/inc/dv_clsmain.asp的truecheckuserlogin函数中
sql=“* 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,userpowe
r,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userid as boardid“
修改为:
sql=“* 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,*_1“
4.checkuserlogin.asp中
response.cookies(“platform“) = usersession.documentelement.*singlenode(“agent/@platform“).text
后添加
response.cookies(“*_1“) = usersession.documentelement.*singlenode(“user*/@*_1“).text
5.index.asp中
response.write(“操作系统:“ &amp; request.cookies(“platform“) &amp; “<br>“)
后添加
response.write(“新增:“ &amp; request.cookies(“*_1“) &amp; “<br>“)
6.ok,圆满完成!
┆◆繁花殿☆┆顶帖组№真爱(ID98458)文字续贴10-21 05:45   更多

发表回复

   


  通知楼主

椅子

┆◆繁花殿☆┆顶帖组丶筱富 ..10-21 07:27
看帖回帖是美德!

回复只看TA

沙发

M`卑微的觊觎.10-21 05:13
这帖不错,该顶!

回复只看TA