ASP个人网站与动网整合非官方方法
时间:2021-06-23 09:22:29|栏目:ASP代码|点击: 次
虽然动网已提供有详细的"动网论坛系统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,圆满完成
上一篇:分页类,异常类
栏 目:ASP代码
下一篇:asp 数据库连接函数代码
本文标题:ASP个人网站与动网整合非官方方法
本文地址:http://www.codeinn.net/misctech/146921.html