php同步登陆方案,网站与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清空以将刚注册的会员加入今日到访会员中

相关的函数库:

//**************与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

$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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值