<?php 
defined('ISDVBBS') or exit('Access Denied');
(substr($passport['colientaddresses'],-1,1)!="/")&&($passport['colientaddresses'].="/");
(false!==$dpos=strpos($passport['colientaddresses'],",")) AND ($passport['colientaddresses']=substr($passport['colientaddresses'],0,$dpos));

empty($comeurl) AND ($comeurl = $fsetting['homepage']);
empty($comeurl) AND ($comeurl='index.php');
if(strtolower(substr($comeurl,0,7))!='http://'){
	$baseurl=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
	(false!==$spos=strrpos($baseurl,"/"))&&($baseurl=substr($baseurl,0,$spos));
	$comeurl='http://'.$baseurl."/".$comeurl;
}

$dv_userinfo=array();
$dv_userinfo['logout_id']=get_cookie('logout_id');

$action=($action=='chk'||$action=='login')?'login':'logout';

if($action=='login'){
$query=$db->query("select username,userpassword as password,useremail as email,userpost,usertopic,usersign,usersex as sex
,userwealth,usercp,userep,userquesion as question,useranswer as answer,userbirthday as birthday from {$dv}user where userid={$userid}");
$dv_userinfo=$db->fetch_array($query);
$dv_userinfo['cookiedate']=get_cookie('selected_cookiedate');
$dv_userinfo['time']=time();
$dv_userinfo['userhidden']=get_cookie('userhidden');
}

$url=makeRpcUrl($action,$passport['colientaddresses'],$comeurl,$dv_userinfo,$passport['passport_pkey']);
function makeRpcUrl($action,$jumpurl,$forward,$dv_userinfo,$passport_pkey){
	$struserinfo = '';
	$allowpassactions=array("login","logout");
	$md5pkey	= md5($passport_pkey);
	foreach($dv_userinfo as $key=>$val)$struserinfo .="&$key=$val";
	($struserinfo!=='') AND ($struserinfo=substr($struserinfo,1));
	$struserinfo = str_replace('=', '', base64_encode(encodexor($struserinfo,$md5pkey)));
	if(in_array($action,$allowpassactions)){
		$verify = md5("{$action}$struserinfo$forward$passport_pkey");
		$url = $jumpurl."passport_client.php?action={$action}&userinfo=".rawurlencode($struserinfo)."&comeurl=".rawurlencode($forward)."&verify=".rawurlencode($verify);
	}else{
		$url="";
	}
	return $url;
}
function encodexor($string,$key)
{
	$len	= strlen($key);
	$code	= '';
	for($i=0; $i<strlen($string); $i++)
	{
		$k		= $i % $len;
		$code  .= $string[$i] ^ $key[$k];
	}
	return $code;
}
?>