加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Discuz! Passport 通行证整合

发布时间:2020-03-22 06:08:52 所属栏目:PHP教程 来源:互联网
导读:请注意: 整合不成功可能造成的后果-----dz论坛无法登录,无法管理

//下面这个函数是discuz的用户cookie编码函数,已修改,原型在$path_bbs/include/global.func.php
function authcode($string, $operation) {
    global $_SERVER, $_DCACHE,$path_bbs;
    require_once "$path_bbs/forumdata/cache/cache_settings.php";//需要获取论坛的authkey
    $discuz_auth_key = md5($_DCACHE['settings']['authkey'].$_SERVER['HTTP_USER_AGENT']);
    $coded = '';
    $keylength = strlen($discuz_auth_key);
    $string = $operation == 'DECODE' ? base64_decode($string) : $string;
    for($i = 0; $i < strlen($string); $i += $keylength) {
        $coded .= substr($string, $i, $keylength) ^ $discuz_auth_key;
    }
    $coded = $operation == 'ENCODE' ? str_replace('=', '', base64_encode($coded)) : $coded;
    return $coded;
}
?>
<?php
if(@$_COOKIE['myusername']==''){
?>
<form action="" method="POST">
用户名:<input>测试用户名为admin,请更改为你的用户名<br>
密码:<input type="password">测试密码为123456<br>
<input type="submit" value="测试">
</form>
<?php
}
else echo("登陆成功,<a href='http://www.jb51.net/article/{$path_bbs}index.php' target=_blank>请到论坛检查登陆</a><br><a href='http://www.jb51.net/article/?act=logout'>退出登陆</a> ");
?>

第六篇 C#与discuz5.0的整合实例

using System;
using System.Security.Cryptography;
using System.Text;

/// <summary>
/// c#与discuz的passport整合事例
/// 请保留以下信息以备出现问题时使用
/// 整合贡献:huozhe3136 QQ:2666556
/// 调试工具:Microsoft Visual Web Developer 2005
/// </summary>
public partial class _Default : System.Web.UI.Page {
    //------------------------需要修改的设置---------------------------------
    string webUrl           = ":1627/webapp/Default.aspx";//这里修改为你的测试主站的地址,不要缺少最后的'http://www.jb51.net/'号
    string dzUrl            = ":8080/discuz/";//这里修改为你的dz地址,不要缺少最后的'http://www.jb51.net/'号
    string dzPassportKey    = "1234567890";//这里修改为你的dz后台通行证设置里的possportkey
    string dzForward        = "";
    string dzAuth           = "";
    string dzVerify         = "";

protected void Page_Load(object sender, EventArgs e){
        dzForward = Request.QueryString["forward"];
        if (Request.QueryString["act"] == "logout") logout();
        if(Session["username"]!=null) Response.Write(Session["username"].ToString()+ "登陆成功! <a href=http://www.jb51.net/article/"default.aspx?act=logout">点击这里退出登陆</a> <a href="http://www.jb51.net/article/+dzUrl+" target=_blank>访问论坛</a><br>");
    }

protected void logout(){
        Session["username"] = null;
        dzForward           = Request.QueryString["forward"];//获取返回地址
        if (dzForward == "") dzForward = webUrl;//如果返回地址为空,则返回设置的页
        dzVerify            = md5("logout" + dzForward + dzPassportKey);
        dzForward           = Server.UrlEncode(dzForward);
        Response.Redirect(dzUrl + "api/passport.php?action=logout&auth=http://www.jb51.net/article/&forward=" + dzForward + "&verify=" + dzVerify);

    }


    protected void Button1_Click(object sender, EventArgs e){
        string postUsername;
        string postPwd;
        postUsername        = username.Text.ToString().Trim();
        postPwd             = password.Text.ToString();

if(postUsername=="admin" && postPwd=="123456"){
            Session["username"]=postUsername;//设置主站自身的cookie或session;

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读