个人网站与动网整合非官方方法

个人网站如有会员注册模块+动网论坛的话,那网站要与动网论坛系统整合,实现不同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("用户名:" & 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,未对其他版本做进行测试,大家有时间都可测下,望告知结果。凌晨五点了,睡觉先...

2008-06-09说明:
上边修改方法只对Dvbbs8.0(含8.0)以下版本有效,而对Dvbbs8.1(含8.1)以上版本,CheckUserLogin.asp需稍做修改:
<%
Set Dvbbs = New Cls_Forum
%>
<!--#Include File="bbs/inc/Dv_ClsMain.asp"-->
<%
Function CheckUserLogin()
    Dim UserSession
    Const MsxmlVersion=".3.0"
    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
%>


上一篇: ASP中Cache技术的应用
下一篇: 用GetRows获取全部记录语法
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 7 | 引用: 0 | 查看次数: 9278
dnawo[2007-11-18 10:01 PM | | | 220.250.0.187 | del | 回复回复]
6#
[quote]知不知道8.1的怎么整合[/quote]
还是用它们提供的接口进行整合吧,好好研究一下,那样更快。
很早前就想再写一篇怎么用他们的接口进行整合的,一直没去写,过段时间再看下
andy7777[2007-11-16 03:07 PM | | | 222.182.5.92 | del | 回复回复]
5#
知不知道8.1的怎么整合
dnawo[2007-08-23 10:30 AM | | | 220.160.25.205 | del | 回复回复]
4#
[quote]请问一下 ,怎么去掉登录验证码的 ?[/quote]
登录后台→基本设置  中找下去掉登录验证码
sakura[2007-08-23 10:20 AM | | | 60.191.108.208 | del | 回复回复]
地板
请问一下 ,怎么去掉登录验证码的 ?
路人甲[2007-05-26 05:05 PM | | | 222.246.50.245 | del | 回复回复]
板凳
谢谢您的分享!木子屋是最棒的
老破[2007-05-18 08:49 PM | | | 218.83.107.80 | del | 回复回复]
沙发
这方法貌似笨笨的。
同时退出,只要将要整合的系统的所有Cookies全部注销就可以了。
同时登录,只要将要整合的系统的所有Cookies全部写入一下就可以了。
同时注册无论在哪里注册,在写入注册信息时,同时将注册信息写入到其它系统的数据库里,并且补齐一些必要的默认初始用户信息;另外还要将要整合的系统的所有Cookies全部更新一下就可以了。
发表评论
登录后再发表评论!