您现在的位置: 365建站网 > 365文章 > 网站与phpwind论坛的同步登陆的解决方案

网站与phpwind论坛的同步登陆的解决方案

文章来源:365jz.com     点击数:809    更新时间:2009-09-13 10:47   参与评论

 网站与phpwind论坛的同步登陆问题是困扰着许多phpwind二次开发人员的难题,这里我详细分析一下这个问题:

1.先开通 phpwind 的通行证
2.在通行证设定的访问入口的后台程序里添加如下代码:

   //pw = phpwind 的安装前缀
   //判断pw中是否有该会员数据
   $sql = "select uid from pw_members where username = '".$username."'";
   $query = $DB->query($sql);
   $row_pw = $DB->fetch_array($query);
   if($row_pw['uid'] <= 0)   
   {
     //插入该会员数据到phpwind的pw_members表
     $sql = "insert into pw_members(uid,username,password,email,publicmail,groupid,memberid,icon,gender,regdate,signature,introduce,location,bday,receivemail,yz,signchange) values (".$row['id'].",'".$username."','".$password."','".$row['email']."',1,-1,8,'',0,'".$row['addtime']."','','".$row['description']."','".$row['address']."',".date("Y-m-d",time()).",1,1,1)";
     $DB->query($sql);
     
     $winduid=$DB->insert_id();
     
     //插入数据到phpwind的pw_memberdata表
        $DB->query("INSERT INTO pw_memberdata (uid,postnum,rvrc,money,lastvisit,thisvisit,onlineip) VALUES ('$winduid', '0', '0', '0', '" . time() . "', '" . time() . "', '')");
     $DB->query("UPDATE pw_bbsinfo SET newmember='".$username."',totalmember=totalmember+1 WHERE id='1'");
   }
   
   //与phpwind登陆同步,原理:共用cookie
   $cktime = 0;
   Cookie("winduser",StrCode($_SESSION['uid']."\t".PwdCode($password)),$cktime);
   Cookie("ck_info",$db_ckpath."\t".$db_ckdomain);
   Cookie('lastvisit','',0);//将$lastvist清空以将刚注册的会员加入今日到访会员中


相关的函数库:
 
<?php
//**************与phpwind做登陆同步的函数****************//
//其中 $GLOBALS['db_hash'] 为 phpwind 通信证的密码或密钥
$timestamp = time();
function PwdCode($pwd){
    return md5($_SERVER["HTTP_USER_AGENT"].$pwd.$GLOBALS['db_hash']);
}

function SafeCheck($CK,$PwdCode,$var='AdminUser',$expire=1800){
    global $timestamp;
    if ($timestamp-$CK[0]>$expire || $CK[2]!=md5($PwdCode.$CK[0])) {
        Cookie($var,'',0);
        return false;
    }
    $CK[0] = $timestamp;
    $CK[2] = md5($PwdCode.$CK[0]);
    Cookie($var,StrCode(implode("\t",$CK)));
    return true;
}

function StrCode($string,$action='ENCODE'){
    $action != 'ENCODE' && $string = base64_decode($string);
    $code = '';
    $key  = substr(md5($_SERVER['HTTP_USER_AGENT'].$GLOBALS['db_hash']),8,18);
    $keylen = strlen($key); $strlen = strlen($string);
    for ($i=0;$i<$strlen;$i++) {
        $k        = $i % $keylen;
        $code  .= $string[$i] ^ $key[$k];
    }
    return ($action!='DECODE' ? base64_encode($code) : $code);
}

function GetCookie($Var){
    return $_COOKIE[CookiePre()."_$Var"];
}

function CookiePre(){
    static $pre = null;
    !isset($pre) && $pre = substr(md5($GLOBALS['db_sitehash']),0,5);
    return $pre;
}

function Cookie($ck_Var,$ck_Value,$ck_Time='F',$p=true,$ck_Httponly=true){
    global $db_ckpath,$db_ckdomain,$timestamp;
   
    if (!$_SERVER['REQUEST_URI'] || ($https = @parse_url($_SERVER['REQUEST_URI']))===false) {
        $https = array();
    }
    if ((empty($https['scheme']) && ($_SERVER['HTTP_SCHEME']=='https' || $_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS'])!='off')) || $https['scheme']=='https') {
        $ck_Secure = true;
    } else {
        $ck_Secure = false;
    }
   
    !$db_ckpath && $db_ckpath = '/';
    $p && $ck_Var = CookiePre()."_$ck_Var";
    if ($ck_Time=='F' || $ck_Time!=31536000) {
        $ck_Time = $timestamp+31536000;
    } elseif ($ck_Value=='' && $ck_Time==0) {
        return setcookie($ck_Var,'',$timestamp-31536000,$db_ckpath,$db_ckdomain,$ck_Secure);
    }
    if (PHP_VERSION>='5.2.0') {
        return setcookie($ck_Var,$ck_Value,$ck_Time,$db_ckpath,$db_ckdomain,$ck_Secure,$ck_Httponly);
    } else {
        return setcookie($ck_Var,$ck_Value,$ck_Time,$db_ckpath.($ck_Httponly ? '; HttpOnly' : ''),$db_ckdomain,$ck_Secure);
    }
}

function Loginout(){
        //注销用户函数
   global $DB,$timestamp,$db_onlinetime,$groupid,$windid,$winduid,$db_ckpath,$db_ckdomain;
   $thisvisit=$timestamp-$db_onlinetime*1.5;
   $DB->query("UPDATE pw_memberdata SET thisvisit='$thisvisit' WHERE uid='$winduid' ");
   list($db_ckpath,$db_ckdomain)=explode("\t",GetCookie('ck_info'));
   Cookie('winduser','',0);
   Cookie('hideid','',0);
   Cookie('lastvisit','',0);

   Cookie('ck_info','',0);
}

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (809人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号