网站与phpwind论坛的同步登陆问题是困扰着许多phpwind二次开发人员的难题,这里我详细分析一下这个问题:
1.先开通 phpwind 的通行证 function SafeCheck($CK,$PwdCode,$var='AdminUser',$expire=1800){ function StrCode($string,$action='ENCODE'){ function GetCookie($Var){ function CookiePre(){ function Cookie($ck_Var,$ck_Value,$ck_Time='F',$p=true,$ck_Httponly=true){ function Loginout(){ Cookie('ck_info','',0);
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']);
}
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;
}
$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);
}
return $_COOKIE[CookiePre()."_$Var"];
}
static $pre = null;
!isset($pre) && $pre = substr(md5($GLOBALS['db_sitehash']),0,5);
return $pre;
}
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);
}
}
//注销用户函数
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);
}
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛