雖然動網已提供有詳細的"動網論壇系統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,圓滿完成