ASP个人网站与动网整合非官方方法
2018-09-06 10:43
虽然动网已提供有详细的动网论坛系统Api接口开发人员指南,但像我这样的菜鸟一时半会可是参详不透的,汗。不甘心,在对其登录、验证等函数进行一番研究再加以测试后最终竟也小有所成,菜鸟也有菜鸟的办法:
本次测试的论坛版本为Version7.1.0Sp1,未对其他版本做进行测试
一、网站文件结构
┝index.asp
┝CheckUserLogin.asp
┕bbs/
二、整合原理
对于同步更新实现不困难,整合主要问题就是难在同步登录,所以我们的重点都将放在讨论如何实现同步登录上。我的方法是将主站用户表整合至动网用户表Dv_User中(免去以后得更新两个库的麻烦),可按需要在Dv_User新增字段,并对bbs/login.asp和bbs/inc/Dv_ClsMain.asp做适当的修改;登录时将表单发至bbs/login.asp进行验证;主站根据动网登录成功后在Session记录的信息判断是否登录成功,并取得用户资料。
三、新增修改文件
<html>
<head>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/>
<title>个人网站与动网整合(
</head>
<body>
<!--#includefile=CheckUserLogin.asp-->
<%
IfCheckUserLoginThen
Response.write(<ahref=bbs/logout.asp?back=1>退出登陆</a><p></p>)
Response.write(用户名kies(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
%>
<formid=form1name=form1method=postaction=bbs/login.asp?action=chk&back=1>
用户名:
<inputname=usernametype=textid=usernamesize=10/>
<br/>
密码:
<inputname=passwordtype=passwordid=passwordsize=10/>
<inputtype=submitname=Submitvalue=登录/>
</form>
<%
Endif
%>
<p></p><ahref=bbs/>进入论坛</a>
</body>
</html>
2.CheckUserLogin.aspcode:
<!--#IncludeFile=bbs/inc/Dv_ClsMain.asp-->
<%
FunctionCheckUserLogin()
DimDvbbs,UserSession
ConstMsxmlVersion=.3.0
SetDvbbs=NewCls_Forum
SetUserSession=Server.CreateObject(msxml2.FreeThreadedDOMDocument&MsxmlVersion)
IfUserSession.loadxml(Session(Dvbbs.CacheName&UserID)&)Then
IfUserSession.documentElement.selectSingleNode(userinfo/@userid).text<>0Then
在论坛登录成功
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).text0为女,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
IfUserSession.documentElement.selectSingleNode(userinfo/@usersex).text=0Then
Response.Cookies(sex)=靓妹
Else
Response.Cookies(sex)=酷哥
Endif
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
Endif
Else
未访问过论坛
CheckUserLogin=False
Endif
SetUserSession=nothing
SetDvbbs=nothing
EndFunction
%>
3.bbs/login.asp新增红色部分,使在站点首页登录成功后仍能返回首页:
Dimcomeurlname
Ifinstr(lcase(request(comeurl)),reg.asp)>0orinstr(lcase(request(comeurl)),login.asp)>0ortrim(request(comeurl))=Then
comeurlname=
comeurl=index.asp
Else
comeurl=request(comeurl)
comeurlname=<li><ahref=&request(comeurl)&>&request(comeurl)&</a></li>
EndIf
Ifrequest(back)=1Then
Response.Redirect(../index.asp)
EndIf
DimTempStr
TempStr=template.html(2)
IfDvbbs.Forum_ChanSetting(0)=1AndDvbbs.Forum_ChanSetting(10)=1AndDvbbs.Forum_ChanSetting(12)=1Then
TempStr=Replace(TempStr,{$ray_logininfo},template.html(3))
Else
TempStr=Replace(TempStr,{$ray_logininfo},)
EndIf
-----------------------------------------------------------------
系统整合
-----------------------------------------------------------------
IfDvApi_EnableThen
Response.WriteDvApi_SaveCookie
Response.Flush
EndIf
-----------------------------------------------------------------
TempStr=Replace(TempStr,{$ray_logininfo},)
TempStr=Replace(TempStr,{$comeurl},comeurl)
TempStr=Replace(TempStr,{$comeurlinfo},comeurlname)
TempStr=Replace(TempStr,{$forumname},Dvbbs.Forum_Info(0))
Response.WriteTempStr
TempStr=
EndFunction
4.bbs/logout.asp新增红色部分,使在站点首页点退出登录后仍能返回首页:
-----------------------------------------------------------------
系统整合
-----------------------------------------------------------------
DimDvApi_Obj,DvApi_SaveCookie,SysKey
IfDvApi_EnableThen
Md5OLD=1
Md5OLD=0
SetDvApi_Obj=NewDvApi
DvApi_SaveCookie=DvApi_Obj.SetCookie(SysKey,Dvbbs.MemberName,,)
SetDvApi_Obj=Nothing
Response.WriteDvApi_SaveCookie
Response.Flush
EndIf
Ifrequest(back)=1Then
Response.Redirect(../index.asp)
EndIf
-----------------------------------------------------------------
Response.RedirectDvbbs.Forum_Info(11)
response.write<scriptlanguage=JavaScript>
response.writesetTimeout(window.location=&Dvbbs.Forum_Info(11)&,1000);
response.write</script>
四、动网设置:去掉登录验证码,OK,整合完毕。
五、扩展:
默认Dv_User表中的字段有些时候并不能满足我们的实际需求,我们就需要新增字段对其进行扩展,动手吧:
1.打开Dv_User表新增一文本类型字段info_1
2.bbs/login.asp的ChkUserLogin函数中
Sql=SelectUserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,lastloginascometime,LastLoginasactivetime,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,useridasboardid
修改为:
Sql=SelectUserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,lastloginascometime,LastLoginasactivetime,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,useridasboardid,info_1
3.bbs/inc/Dv_ClsMain.asp的TrueCheckUserLogin函数中
Sql=SelectUserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLoginascometime,LastLogin,LastLoginasactivetime,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,useridasboardid
修改为:
Sql=SelectUserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLoginascometime,LastLogin,LastLoginasactivetime,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,useridasboardid,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,圆满完成
上一篇:15种ASP技巧
下一篇:Asp 编码互转的研究和实现代码